[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] What is the effect of `kill -s INT -$$` within the INT t

From: Chet Ramey
Subject: Re: [Help-bash] What is the effect of `kill -s INT -$$` within the INT trap of the same script?
Date: Thu, 27 Dec 2018 13:31:20 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 12/25/18 6:49 AM, Peng Yu wrote:
>> Bash tries to prevent recursive trap handler invocations. ksh93 and dash,
>> for instance, are happy to run the trap handler until the process runs out
>> of stack space and the kernel kills it.
> OK. The C library allows handling multiple INT. I typed ctrl-C twice
> and the handle was called twice as shown below.

Those are the semantics for Unix signal handling.

> Bash only accepts the signal once. For example, if I try to kill a
> process started the following script the trap only is called once. How
> does Bash know to only handle a signal of a given signal type once?

Those are two different things. Signals are states, not counters (execpt
for the special case of SIGCHLD). Bash receives the signal twice, but does
not allow the trap handler to be run recursively, and resets the `trap
handled' state when the trap handler completes.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden

reply via email to

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