[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: prevent ignore SIGINT for asynchronous commands without enabling job
From: |
konsolebox |
Subject: |
Re: prevent ignore SIGINT for asynchronous commands without enabling job control |
Date: |
Wed, 10 Apr 2013 21:00:22 +0800 |
It's actually simple with trap. Just catch SIGINT with a function and call
a function to kill the tree:
https://www.linuxquestions.org/questions/blog/konsolebox-210384/bash-functions-to-list-and-kill-or-send-signals-to-process-trees-34624/
Note killtree3. And that could be merged as one single function per your
own preference.
And do killtree3 "$BASHPID".
On Wed, Apr 10, 2013 at 6:43 PM, Ilya Basin <basinilya@gmail.com> wrote:
> Hi.
> I have a script that creates some background tasks.
> I want the whole tree to be killed by Ctrl-C.
>
> There's a requirement that the script process and its children must
> belong to the same process group. This is why I can't enable job
> control.
>
> I don't want to use 'trap', because it adds complexity.
>
> Example:
>
> #!/bin/bash
> sleep 90 &
> wait $!
>
> After Ctrl-C "sleep 90" stays.
>
> Using trap:
>
> #!/bin/bash
>
> trap 'trap - INT; kill -TERM $noeof_pid; kill -INT $$' INT
>
> sleep 90 &
> wait $