[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Does the parent get the trap signal when the child is ru
Re: [Help-bash] Does the parent get the trap signal when the child is running in the foreground?
Tue, 11 Dec 2018 11:01:44 -0500
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
On 12/10/18 12:25 PM, Peng Yu wrote:
> I am not sure if I understand the traps related with parent and child
> processes correctly.
> I press Ctrl-C 5 times. The child gets SIGINT 5 times and the parent
> gets 1 once. But since Ctrl-C triggers SIGINT for the process group
> whose leader is the process started by main1.sh, why main1.sh only
> gets one signal? Thanks.
The parent receives 5 SIGINTs, but only runs the trap once, when the
child process completes.
Read https://www.cons.org/cracauer/sigint.html for more insight about the
The parent shell shouldn't really do anything, since the child -- the
foreground process -- caught the SIGINT, handled it, and did not exit as a
result. However, backwards compatibility and user expectations being what
they are, the parent shell (main1.sh) runs the SIGINT trap as well.
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/