bug-bash
[Top][All Lists]
Advanced

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

Re: [External] : Re: receiving SIGHCHLD if job control is disabled - exp


From: Vladimir Marek
Subject: Re: [External] : Re: receiving SIGHCHLD if job control is disabled - expected behavior?
Date: Fri, 1 Oct 2021 17:02:27 +0200

On Fri, Oct 01, 2021 at 09:39:50AM -0400, Chet Ramey wrote:
> 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://urldefense.com/v3/__https://www.mail-archive.com/austin-group-l@opengroup.org/msg00898.html__;!!ACWV5N9M2RV99hQ!armiksAJmuzyNkkBHbfa18QJRpAVznB58TP1DqCZ76ejwxGwRLeLm3yLz4VknKozRUA$
> 
> 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.

Thank you, that makes sense.



> > 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.

Ah, of course :)

Thank you
-- 
        Vlad



reply via email to

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