On Thu, 12 Dec 2002 17:43:34 +0100, [EMAIL PROTECTED] (Olivier Moulene) wrote:
>I have the pid of one running process and i want to kill it and all its children. >What can i do to know the pids of every children ? This untested code from perlmonks.org, it might give you some ideas. What you are after is in the killchd subroutine. ############################################################## #!/usr/bin/perl use warnings; use strict; #by robau of perlmonks #This subroutine takes two arguments, the parent process ID #and the numeric signal to pass to the processes #(which would be 9 if you wanted to issue a -TERM). #Using Proc::Process you could find the process ID #of the process login -- zentara with something similar #to the following : my $proc = Proc::ProcessTable->new; my @ps = map { $_->pid if ($_->cmndline =~ /login -- zentara/) } @{$proc->table}; &killchd($_, 9) foreach @ps; #killchd(9895, 9); #kill -9 process 9895 sub killchd ($;$) { use Proc::ProcessTable; my $sig = ($_[1] =~ /^\-?\d+$/) ? $_[1] : 0; my $proc = Proc::ProcessTable->new; my %fields = map { $_ => 1 } $proc->fields; return undef unless exists $fields{'ppid'}; foreach (@{$proc->table}) { kill $sig, $_->pid if ($_->ppid == $_[0]); }; kill $sig, $_[0]; }; ########################################################### -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]