Re: Cleaning up background processes

Liste des GroupesRevenir à cu shell 
Sujet : Re: Cleaning up background processes
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell
Date : 09. May 2024, 01:06:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v1h0hk$7rkr$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 08.05.2024 23:04, vallor wrote:
On Mon, 6 May 2024 12:08:39 -0000 (UTC), gazelle@shell.xmission.com (Kenny
McCormack) wrote in <v1ah87$l0a8$1@news.xmission.com>:
 
In article <20240505214609.114@kylheku.com>,
Kaz Kylheku  <643-408-1753@kylheku.com> wrote:
On 2024-05-05, Christian Weisgerber <naddy@mips.inka.de> wrote:
Is there a standard POSIX shell idiom to clean up background
processes?
>
You have a shell script that starts some background process with &.
Now you want to make sure that the background process terminates when
the shell script terminates.  In particular, when it terminates due to
special circumstances.
>
Maybe have an EXIT trap which calls wait?

'wait' wouldn't abort the process (as the OP seems to have required).

>
The fundamental underlying problem here is that the EXIT trap is only
called on a "normal" exit.  In particular, it does not get called under
(at least) the following circumstances:
>
    1) User hits ^C causing the script to abort.
 
I'm sorry, but I've waited and nobody said anything, so

I hadn't answered because it doesn't work as had been advertised. With

  trap 'echo INT' INT
  trap 'echo EXIT' EXIT

and hitting ^C I get both signals (INT) and pseudo-signal (EXIT)
in that order (with ksh, bash) [and it makes of course sense]

  INT
  EXIT

so it would be no problem, in my book.

But the pseudo-signal 'EXIT' is non-standard (to my knowledge), so you
cannot generally rely on it, depending on your environment, and the OP
asked for a "standard POSIX shell idiom".

I have to ask:  Why couldn't you trap "kill -1 0" INT?

Storing PIDs and killing the respective processes on exit is something
I had done in the past, making use of the process groups is something
I'd also consider; both things you already proposed upthread, IIRC.

Janis

[...]


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