我有一个信号处理程序,我将ctrl + z / SIGTSTP设置为只能被程序检测到。但是当我想将ctrl + z / SIGTSTP的信号处理程序更改为子进程中的默认行为时,ctrl + z不会改变。是否有适当的改变信号处理程序?
#include <stdio.h>
#include <signal.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
void handler(int sig_num)
{
printf("detected %d\n",sig_num);
}
int main()
{
int x;
signal(SIGTSTP,handler);
pid_t pid = fork();
if(pid == 0)
{
signal(SIGTSTP,SIG_DFL);
printf("in child process \n");
while(1);
}
else if(pid > 0)
{
printf("running parent\n");
printf("waiting for my child to run\n");
wait(&x);
exit(0);
}
return 0;
}