|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
How do I track and kill all sub processes of a (korn) shell?
I usually do it via using the ksh monitor option to create a particular process group id which later can be killed together with all further offspring. Now this fails if the sub proc creates its own pgid like in the following example subproc.ksh: #!/bin/ksh set -m sleep 300& and here is the monitoring script: #!/bin/ksh set -m subproc.ksh& PID=$! # and try to kill the background process after 10 seconds sleep 10 kill -15 -$PID This will kill all processes with pgid=$PID but there are none since subproc.ksh created its own pgid so subproc.ksh will still exist after the monitoring script has ended. If subproc.ksh would not do this pgid setting it could be tracked and killed. Any idea how to catch such detached processes which show ppid=1 (so they are not in the process tree of the current process) and which create their own pgid? (the point of this story: I need to monitor a set of apps which I do not own so I cannot influence whether they behave nicely or not, means: I don't have access to subproc.ksh in real life. Instead of subproc it could be a C-program which does the same pgid creation but my monitoring needs to kill all apps after a set time) rgds andy |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2008-03-13, andyhaupt@netscape.net <andyhaupt@netscape.net> wrote:
> > > How do I track and kill all sub processes of a (korn) shell? > > I usually do it via using the ksh monitor option to create a > particular process group id which later can be killed together with > all further offspring. > > Now this fails if the sub proc creates its own pgid like in the > following example > > subproc.ksh: > #!/bin/ksh > set -m > sleep 300& > > and here is the monitoring script: > #!/bin/ksh > set -m > subproc.ksh& > PID=$! > # and try to kill the background process after 10 seconds > sleep 10 > kill -15 -$PID > > This will kill all processes with pgid=$PID but there are none since > subproc.ksh created its own pgid so subproc.ksh will still exist after > the monitoring script has ended. > > If subproc.ksh would not do this pgid setting it could be tracked and > killed. > This looks so obvious there must be something wrong with it, but: kill -15 $PID |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 13 Mrz., 21:40, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 2008-03-13, andyha...@netscape.net <andyha...@netscape.net> wrote: > > > > > How do I track and kill all sub processes of a (korn) shell? > > > I usually do it via using the ksh monitor option to create a > > particular process group id which later can be killed together with > > all further offspring. > > > Now this fails if the sub proc creates its own pgid like in the > > following example > > > subproc.ksh: > > #!/bin/ksh > > set -m > > sleep 300& > > > and here is the monitoring script: > > #!/bin/ksh > > set -m > > subproc.ksh& > > PID=$! > > # and try to kill the background process after 10 seconds > > sleep 10 > > kill -15 -$PID > > > This will kill all processes with pgid=$PID but there are none since > > subproc.ksh created its own pgid so subproc.ksh will still exist after > > the monitoring script has ended. > > > If subproc.ksh would not do this pgid setting it could be tracked and > > killed. > > This looks so obvious there must be something wrong with it, but: > kill -15 $PID there is no process with pid=$PID anymore, this was the ksh which ended, and only the sleep process in the background is left. |
|
![]() |
| Outils de la discussion | |
|
|