PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > kill all sub processes
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

kill all sub processes

Réponse
 
LinkBack Outils de la discussion
Vieux 13/03/2008, 17h31   #1
andyhaupt@netscape.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut kill all sub processes

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
  Réponse avec citation
Vieux 13/03/2008, 20h40   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: kill all sub processes

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


  Réponse avec citation
Vieux 13/03/2008, 22h09   #3
andyhaupt@netscape.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: kill all sub processes

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h40.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12131 seconds with 11 queries