bug-bash
[Top][All Lists]
Advanced

[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: Fri, 12 Apr 2013 08:56:24 +0800

Hi. I made an important update on the functions. I should have include -d
'' to read. Not sure why I didn't notice it during the test back then. The
previous versions would only read a single id but that's fixed now. Good
thing I remembered the code after stumbling upon another problem.

I thought I should just say this just in case you did used them.

Ross


On Wed, Apr 10, 2013 at 9:00 PM, konsolebox <konsolebox@gmail.com> wrote:

> 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 $
>
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]