bug-bash
[Top][All Lists]
Advanced

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

Re: Clarification needed on signal spec EXIT


From: Francis Moreau
Subject: Re: Clarification needed on signal spec EXIT
Date: Tue, 16 Oct 2012 19:39:58 +0200

Thanks for your prompt answer.

On Tue, Oct 16, 2012 at 7:31 PM, DJ Mills <danielmills1@gmail.com> wrote:
> On Tue, Oct 16, 2012 at 1:26 PM, Francis Moreau <francis.moro@gmail.com> 
> wrote:
>> Hi,
>>
>> Currently the description of the builtin trap isn't enough regarding
>> the description of the EXIT signal spec, IMHO.
>>
>> It says: "If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from
>> the shell.", and nothing more, unless I'm missing some other points
>> about it somewhere else (that would be unfortunate too).
>>
>> Specifically, the documentation should specify exactly what "exit from
>> the shell" means: for example killing a shell process makes it exit
>> somehow. Is this is supposed to be handled by EXIT signal spec ?
>>
>> Another thing that should be clarified is what's happening in the
>> context of a subshell ?
>>
>> Thanks
>> --
>> Francis
>>
>
> Anything that causes the shell to exit will trigger the trap (with the
> exception of signals that can't be handled, like KILL).
> That means a normal "exit" command or hitting EOF will trigger it, but
> so will TERM, or INT, etc.

Then I'm confused by this:

--------------
main_cleanup () { echo main cleanup; }
submain_cleanup () { echo sub cleanup; }

trap main_cleanup EXIT

task_in_background () {
        echo "subshell $BASHPID"

        while :; do
                # echo "FOO"
                sleep 1
        done
        echo "subshell exiting..."
}

{
        trap submain_cleanup EXIT
        trap
        task_in_background
} &

echo exiting...
--------------

Sending TERM signal to the subshell doesn't make "submain_cleanup()"
to be called.

>
> What about subshells do you not understand? If the trap is defined
> within a subshell, it will trigger when that subshell exits. If it's
> defined outside, it will not.

I was confused after reading this:

http://bash.2382.n7.nabble.com/Q-bash-trap-in-subshell-td5611.html

thanks
-- 
Francis



reply via email to

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