After a while I can see that both myscript.sh and Aprogram have been dead. However ‘sleep 500 &’ is still running.
一旦Aprogram完成,myscript.sh就会打印出“完成”,并且也会完成. sleep 500以PID 1作为父进程进行处理.这就对了.
Can anyone explain why is this behavior?
当myscript.sh得到它时,SIGINT不会传递给Aprogram.使用strace确保Aprogram不会收到信号.
Also,when I issued SIGINT signal to the ‘myscript.sh’ what exactly is happening?
我首先想到的情况就像当用户按下Ctrl-C并读取这个http://www.cons.org/cracauer/sigint.html时那样.但情况并非完全相同.在你的情况下,shell接收到SIGINT但子进程没有.然而,贝壳在那个时刻有一个儿童过程,它没有做任何事情,并一直在等孩子.在将SIGINT发送到等待子进程的shell脚本之后,这是我的计算机上的strace输出:
>strace -p 30484
Process 30484 attached - interrupt to quit
wait4(-1,0x7fffc0cd9abc,NULL) = ? ERESTARTSYS (To be restarted)
--- SIGINT (Interrupt) @ 0 (0) ---
rt_sigreturn(0x2) = -1 EINTR (Interrupted system call)
wait4(-1,
Why is ‘Aprogram’ getting killed and why not ‘sleep’ ? How is the signal INT getting transmitted to it’s child processes?
据我所知,像你的Aprogram这样的儿童计划并没有被杀死.它没有收到SIGINT并正常完成.一旦完成你的shell脚本也完成了.