[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Clarification needed on signal spec EXIT
From: |
Chet Ramey |
Subject: |
Re: Clarification needed on signal spec EXIT |
Date: |
Sat, 20 Oct 2012 15:01:21 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 |
On 10/16/12 4:00 PM, Bob Proulx wrote:
> Francis Moreau wrote:
>> --------------
>> 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.
>
> And it does in ksh93. Hmm... And it does if I comment out the line
> "trap main_cleanup EXIT". It seems to only set the trap if no trap
> handler was previously set.
Yes, this is a bug in bash-4.2. The subshell doesn't properly reinitialize
the traps if a trap has already been set in the parent. This was fixed in
late July and will be in the next version of bash.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/