子进程调用execv函数后,对信号的处理不保留

子进程会继承父进程的信号处理方式,直到子进程调用exec函数。子进程调用exec函数后,exec将父进程中设置为捕捉的信号变为默认处理方式,其余不变。例如在父进程中把SIGTERM设置为捕捉,SIGINT设置为忽略。子进程执行exec
  1#include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <sys/wait.h>
  5 
  6 int main  ( int argc , char **argv)
  7 {
  8         pid_t pid;
            if (SIG_ERR == signal (SIGINT , SIG_IGN)) 
  9         if ( (pid = fork()) < 0)
 10         {
 11                 printf ("fork error/n");
 12         }
 13         else if (pid  == 0)
 14         {
 15                 execv ("term_int", argv);
 16                 printf ("never get here /n");
 17         }
 18 
 19         wait (NULL);
 20 }    

下面是term_int.c
#include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 
  5 int main()
  6 {
  7         pause();
  8         return 0;
  9 }


这里怎么看子进程与父进程的区别
在第一个主程序后加
wait前
pause();
可以看到
execv后的pause后是能ctrl+c结束的
而主程序中的不能因为有:
if (SIG_ERR == signal (SIGINT , SIG_IGN)) 


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值