git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Easy shell question: how to make a script killing all his childs when killed?

From
Alex Riesen <fork0@t-online.de>
Date
Dec 9, 2006, 17:37 UTC
Message-ID
<20061209173703.GA12373@steel.home>
In-Reply-To
<e5bfff550612090716p215167b9r2277b09c09b18894@mail.gmail.com>
Marco Costalba, Sat, Dec 09, 2006 16:16:32 +0100:
> So how can I write the script to be sure that when stopped, it will
> kill all his childern?

Strictly speaking: you can't. Anything you'd try will either be not portable or involve quiet complex dependencies (like perl). Are you sure you can't control each process independently?

Speaking not so strictly, you can use a script engine which supports either signal handling or exit notification (i.e. sh has traps and perl has %SIG and END{}). It's unsafe, ugly and not quiet portable to that other operating system, but it often works and is (ab)used.

> P.S: I have no way to exec the script in fancy ways, I can just start
> it and get is PID.

Which is "fancy" enough. What do you mean "start"? Starting a new process usually and notably involves forking and execing (even if the first thing to exec will be your shell).

Previous: Marco CostalbaNext: Marco Costalba
Message 2 of 6 in “Easy shell question: how to make a script killing all his childs when killed?”
  1. Marco CostalbaDec 9, 2006
  2. Alex RiesenDec 9, 2006
  3. Marco CostalbaDec 9, 2006
  4. Alex RiesenDec 9, 2006
  5. Marco CostalbaDec 9, 2006
  6. Alex RiesenDec 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.