bug-bash
[Top][All Lists]
Advanced

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

Re: receiving SIGHCHLD if job control is disabled - expected behavior?


From: Chet Ramey
Subject: Re: receiving SIGHCHLD if job control is disabled - expected behavior?
Date: Fri, 1 Oct 2021 09:39:50 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

On 10/1/21 4:24 AM, Vladimir Marek wrote:
Hello,

The code in question is

set +m
echo $BASH_VERSION
echo $SHELLOPTS
trap 'echo =====SIGCHLD=====' 18
sleep 1
echo done


Bash 5 output:
5.0.17(1)-release
braceexpand:hashall:interactive-comments
=====SIGCHLD=====
done


Bash 4 output:
4.4.19(1)-release
braceexpand:hashall:interactive-comments
done



I was trying to find a relevant note in changelog and I found this in 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.

and this in CWRU/changelog:

         - waitchld: run SIGCHLD trap for each child exited even if job control
           is not enabled when in Posix mode. Prompted by an austin-group-l
           discussion

I was trying to find the discussion and the closest thing I found was

https://www.mail-archive.com/austin-group-l@opengroup.org/msg00898.html

That's the one.

A SIGCHLD is generated when a child process dies, whether or not the shell
currently has job control active, since monitor mode is basically about
process groups. You can trap any signal, including SIGCHLD, so why not
make it as reliable as you can?

It's useful to be able to guarantee that you'll get a SIGCHLD trap for
each child exiting, to do exactly the sort of counting that was the subject
of that discussion, so I made that work whether or not monitor mode is
enabled.

The documentation, even though it talks about this feature in the JOB
CONTROL section, never made any distinction.

As a side note, another interesting bit I found is that if I replace the
'sleep 1' with 'read' I will not get SIGCHLD in bash 5.

Well, of course (?). `read' is a builtin, no child process is created, and
so the shell doesn't get a SIGCHLD.

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