help-bash
[Top][All Lists]
Advanced

[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


From: Chet Ramey
Subject: Re: [Help-bash] Does the parent get the trap signal when the child is running in the foreground?
Date: Wed, 12 Dec 2018 12:25:28 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 12/11/18 2:45 PM, Peng Yu wrote:

> The webpage that you mentioned says bash is WCE "wait and cooperative exit".
> 
> """
> WCE The shell exits if a child signaled that it was killed on a signal
> (either it had the default handler for SIGINT or it killed itself).
> """
> 
> The following test cases match the description.
> 
> - ./script_notrap.sh and ./script_resetkilltrap.sh cause the same
> behavior of main.sh (exit immediately).
> - ./script_emptytrap.sh and ./script_exittrap.sh cause the same
> behavior of main.sh (run to the following commands below "$0").
> 
> I am not sure about ./script_kill9trap.sh. As the website does not say
> what kinds of "kill" it refers to. If it refers to all kinds of
> "kill", then the description of the webpage does not match the
> behavior of bash.

Why would you assume that the page, which is completely devoted to SIGINT
and SIGQUIT, would talk about any other signal? It means the child killing
itself with the same signal (SIGINT, in this case) it received.

> Should "The shell exits ..." be changed to "the parent shell's INT is
> trigger once"?

The explanation assumes the parent does not trap SIGINT, since the example
script it uses does not include a trap.

> Also, the implementation of ./script_resetkilltrap.sh still
> technically uses the default handler of SIGINT. Is there a way that
> the default handler is not used but the subshell kill itself and
> causes the parent shell to trigger the INT of the parent shell?

No. The parent knows which signal caused the child to exit. If the child
didn't exit due to SIGINT, the parent won't act as if it received the
SIGINT.

> Also, the implementation of this behavior in bash is intriguing to me.
> How does the parent shell know whether the child uses the default
> handler?

It deduces it. What it does know is whether the child process exited
due to a signal (WIFSIGNALED), and which signal caused it to exit
(WTERMSIG). Since the only way WIFSIGNALED != 0 and WTERMSIG == SIGINT is
if the process was killed due to SIGINT, the disposition had to be SIG_DFL.
It can combine this with the knowledge that it received SIGINT as well, and
can intuit that the signal was sent to the process group and act
accordingly.

-- 
``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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]