【发布时间】:2014-01-02 13:13:15
【问题描述】:
int main() {
int pid = fork();
if(pid > 0){
kill(pid, SIGKILL);
printf("a");
}else{
/* getppid() returns the pid
of the parent process */
kill(getppid(), SIGKILL);
printf("b");
}
}
代码片段的结果可能是:nothing, a, b, ab, ba
我不明白为什么什么都不可能,ab 和 ba。
int a = 1;
void handler(int sig){
a = 0;
}
void emptyhandler(int sig){
}
int main() {
signal(SIGINT, handler);
signal(SIGCONT, emptyhandler);
int pid = fork();
if(pid == 0){
while(a == 1)
pause();
printf("a");
}else{
kill(pid, SIGCONT);
printf("b");
kill(pid, SIGINT);
printf("c");
}
}
这个结果是 bac, bca。
我不确定为什么“进程不会终止”也有效?为什么 SIGINT 会杀死它?
【问题讨论】: