2015-12-16 38 views
2

如果父进程收到ctrl-C信号,我一直试图阻止父父线程杀死子进程。我已经用完了想法。阻止孩子从父进程中获取SIGINT

父进程已准备好捕获SIGINT,所以我想和现在的孩子一样死。

int main() { 
     pid_t pid; 

     pid = fork(); 

     if(pid > 0) { 
      /*Parent proccess*/ 
      [...other code...] 
     } else { 
      /*Child proccess*/ 

      signal(SIGINT, SIG_IGN);  //does not work 
      sigaction(SIGINT, &action, 0); //does not work either 
      [...other code...] 
     } 

    } 

想法?

+0

如果父母的流程已经死亡,让孩子活着的目标是什么? – duDE

+1

子进程杀死它的信号是什么? –

+1

[Linux守护进程]的可能重复(http://stackoverflow.com/questions/3095566/linux-daemonize) – ecatmur

回答

2

SIGINT发送到整个进程组。尝试在子进程中使用setpgrp();将其放入不同的进程组。