我不确定更复杂的信号和问题。来自孩子或父母的信号呼叫有区别吗?如何使用信号叉?
当孩子分叉时,它现在是父母还是孩子只有以前的父母?
由于包含一个处理程序,因此缺省处理程序无效。那么你能否改变SIGINT
以不终止进程?
int count = 0;
void killhandler(int sig){
printf("SIGKILL received\n");
return;
}
void childhandler(int sig){
int status;
wait(&status);
count += WEXITSTATUS(status);
return;
}
main(){
int i; // for loop iterator
pid_t pid[3]; // pids of child processes
Signal(SIGKILL, killhandler);
Signal(SIGCHLD, childhandler);
// Fork 3 child processes
for(i=0; i<3; i++){
pid[i] = fork();
if(!pid[i]){ // If child process
Signal(SIGKILL, SIG_DFL);
exit(5);
}
}
// Parent process only
for(i=0; i<3; i++){
kill(pid[i], SIGKILL);
}
sleep(5);
printf("count = %d\n", count);
exit(0);
}
为什么"SIGKILL received"
从不打印?
为什么只能算为:0,5,10,15