Re: bash continues after kill(self, TERM) on reboot
Chet Ramey <[email protected]> Tue, 3 Mar 2026 15:59:26 -0500
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Organization | ITS, Case Western Reserve University |
| Message-ID | <[email protected]> |
On 3/1/26 2:52 PM, Daniel Villeneuve wrote:
> Hi,
> I'm using GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu),
> on a CentOS Stream 9 machine.
> I am unable to understand what I consider an unexpected behavior from a
> bash script that does the following:
> - use "set -e"
> - install an EXIT trap that takes some time to execute
> - install a TERM trap that just echoes and then re-kills the script
> with TERM
> - start a "sleep infinity" process
> Both traps unset traps for EXIT and TERM on entry.
> On reboot, the TERM signal is not caught immediately because of the
> "sleep" subprocess, which
> is killed and returns an error. Bash then could start the EXIT trap or
> handle the TERM signal.
> What I observe is that it "starts" the EXIT trap but is then
> immediately interrupted by the TERM signal.
It probably runs the EXIT trap due to the SIGHUP, which is not included
in your testing. I didn't test anything, just looked at the strace
output.
>
> wait4(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGTERM}], 0, NULL) = 3130
> --- SIGHUP {si_signo=SIGHUP, si_code=SI_USER, si_pid=1, si_uid=0} ---
> --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=1, si_uid=0} ---
> rt_sigreturn({mask=[CHLD]}) = 3130
> --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} ---
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
(application/pgp-signature, 203 B)
-----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQR8ATX7CIqvbGbGULm7WGnwZOp0qwUCaadLrgUDAAAAAAAKCRC7WGnwZOp0q7fY AKCM0jRqEXuodkZyNq46oBTvqVSAFwCfdKKUJMV4AgTZC/HS9ZmdZsfasBM= =5clI -----END PGP SIGNATURE-----