Sujet : Re: Cleaning up background processes
De : geoff (at) *nospam* clare.See-My-Signature.invalid (Geoff Clare)
Groupes : comp.unix.shellDate : 13. May 2024, 15:14:40
Autres entêtes
Message-ID : <0bg9hk-j2r.ln1@ID-313840.user.individual.net>
References : 1 2 3 4 5 6
User-Agent : Pan/0.154 (Izium; 517acf4)
Christian Weisgerber wrote:
Instead of
foo &
I can run
(trap - INT; exec foo) &
and indeed that seems to restore the default behavior, i.e., terminate
the process, for both FreeBSD sh and bash. Anybody see any problem
with that approach?
It doesn't/didn't work in some shells, according the POSIX rationale
(XRAT C.2.11 "Signals and Error Handling"):
Historically, some shell implementations silently ignored attempts
to use trap to set SIGINT or SIGQUIT to the default action or to
set a trap for them after they have been set to be ignored by the
shell when it executes an asynchronous subshell (and job control
is disabled). This behavior is not conforming. For example, if a
shell script containing the following line is run in the
foreground at a terminal:
(trap - INT; exec sleep 10) & wait
and is then terminated by typing the interrupt character, this
standard requires that the sleep command is terminated by the
SIGINT signal.
I don't know which shells were affected or whether any might still
be in use (without the behaviour having been corrected).
I'd also be interested in historical insights how this "ignore SIGINT
for asynchronous processes" behavior came to be.
That's how shells behaved before job control was invented. It was
how you could interrupt a foreground process without the signal
affecting background processes.
-- Geoff Clare <netnews@gclare.org.uk>