Re: Cleaning up background processes

Liste des GroupesRevenir à cu shell 
Sujet : Re: Cleaning up background processes
De : geoff (at) *nospam* clare.See-My-Signature.invalid (Geoff Clare)
Groupes : comp.unix.shell
Date : 13. May 2024, 14: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>

Date Sujet#  Auteur
5 May 24 * Cleaning up background processes17Christian Weisgerber
5 May 24 +- Re: Cleaning up background processes1Lawrence D'Oliveiro
5 May 24 +- Re: Cleaning up background processes1Christian Weisgerber
6 May 24 +- Re: Cleaning up background processes1vallor
6 May 24 `* Re: Cleaning up background processes13Kaz Kylheku
6 May 24  `* Re: Cleaning up background processes12Kenny McCormack
8 May 24   +* Re: Cleaning up background processes9vallor
9 May 24   i+* Re: Cleaning up background processes4Janis Papanagnou
10 May 24   ii`* Re: Cleaning up background processes3Geoff Clare
10 May 24   ii `* Re: Cleaning up background processes2Janis Papanagnou
19 May 24   ii  `- Re: Cleaning up background processes1Martijn Dekker
11 May 24   i`* Re: Cleaning up background processes4Christian Weisgerber
11 May 24   i `* Re: Cleaning up background processes3Kenny McCormack
12 May 24   i  `* Re: Cleaning up background processes2Christian Weisgerber
13 May 24   i   `- Re: Cleaning up background processes1Geoff Clare
11 May 24   `* Re: Cleaning up background processes2Christian Weisgerber
11 May 24    `- Re: Cleaning up background processes1Kenny McCormack

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal