help-bash
[Top][All Lists]
Advanced

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

Re: Different handling of "trap" in bash 4.4.20(1)-release (x86_64-pc-li


From: Chet Ramey
Subject: Re: Different handling of "trap" in bash 4.4.20(1)-release (x86_64-pc-linux-gnu) and bash version 5.2.15(1)-release (x86_64-aeos5-linux-gnu)
Date: Tue, 3 Oct 2023 15:43:29 -0400
User-agent: Mozilla Thunderbird

On 9/27/23 5:08 AM, MESSNER Andreas via wrote:
Classified as: {OPEN}

Hello,

I have a question concerning "trap"  handling in bash
Script for testing:
#/bin/bash

function cleanup ()
{
     echo "Executing cleanup"

     # trying to kill non-existing process
     killall doesnotexist >/dev/null 2>&1
     killall doesnotexist >/dev/null 2>&1

     echo "Leaving cleanup"
}
trap cleanup INT CHLD

echo "Calling cleanup"
cleanup
echo "Back from cleanup"

sleep 1

Executing the script in bash 4.4.20(1) shows the following result:
Calling cleanup
Executing cleanup
Leaving cleanup
Back from cleanup

Executing the script in bash 5.2.15(1) shows the following result:

The change came in bash-5.0. From CHANGES:

n. The SIGCHLD trap is run once for each exiting child process even if job
   control is not enabled when the shell is in Posix mode.

(That isn't strictly correct; the SIGCHLD behavior is in effect even when
the shell is not in Posix mode.)

This made the behavior the same whether or not job control was enabled.
There was nothing in the documentation to imply it was limited. It also
allows recursive (nested) trap command execution if a SIGCHLD arrives
during the execution of a SIGCHLD trap.

There was a lively austin-group (POSIX) discussion about this back in
April, 2017.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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