parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alternate termination sequence option --term-seq


From: Martin d'Anjou
Subject: Re: Alternate termination sequence option --term-seq
Date: Tue, 28 Apr 2015 14:31:16 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 15-04-27 05:06 PM, Ole Tange wrote:

Do I want to send the signal to the process group or just the process
To me it makes sense to first terminate the parent process and let it
terminate its own children, as it is a valid way of writing programs (see
http://mywiki.wooledge.org/SignalTrap).

If processes remain after the first pass, reapply the termination sequence
to the process group.
This you have to elaborate. Explain how this --termseq is executed
(with special emphasis on process groups):

--termseq HUP,2,TERM,10,TERM,20,INT,30,KILL


Let's assume that the user calls GNU Parallel and wants two iterations:
parallel [options] --termseq HUP,2,TERM,10,TERM,20,INT,30,KILL cmd ::: 1 2

Assume that it is time to apply the termination sequence and that the two jobs are still running. Assume that the user command "cmd" spawns other processes, so there is a process tree below the "cmd". GNU Parallel has two children processes, and GNU Parallel is the grand-parent of the children's children, and so on. Could be deep or not, we don't know.

cmd[0] -> child[0..N] -> grandchild[0..M] -> ...
cmd[1] -> child[0..P] -> grandchild[0..Q] -> ...

When GNU Parallel sends the termination sequence, it should only send it to the cmd[0] and cmd[1] processes. Since GNU Parallel does not know whether the cmd processes trap signals, it has to give them the benefit of the doubt and let them kill their own children processes.

So let's say GNU Parallel sends HUP to cmd[0] and cmd[1], not to the children nor to the grandchildren. It would unfold as follows:

After 2 seconds, if one or both cmd processes are still alive, GNU Parallel sends the TERM signal to the cmd processes still alive. After 10 seconds, if one or both cmd processes are still alive, GNU Parallel sends the TERM signal to the cmd processes still alive. After 20 seconds, if one or both cmd processes are still alive, GNU Parallel sends the INT signal to the cmd processes still alive. After 30 seconds, if one or both cmd processes are still alive, GNU Parallel sends the KILL signal to the cmd processes still alive.

Now GNU Parallel looks at the whole process tree, all the way down to the last child. If any process remains, GNU parallel sends the termination sequence to all of them.

So as soon as the cmd processes are gone, GNU Parallel looks at the whole process tree, and sends the termination sequence to all of them.

The whole purpose of doing this is to give the top level "cmd" processes the chance to kill their own child processes. If the cmd processes don't kill their own child processes, it does cost GNU Parallel more time.

That's how I picture it in my mind.

Martin



reply via email to

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