As I'm a great proponent of implementing in Perl rather than relying on external programs, I came up with the following more generic code which is a bit cleaner in that it doesn't depend on the external execution of ps :
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];
};
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 -- mrc with something similar to the following :
my $proc = Proc::ProcessTable->new;
my @ps = map { $_->pid if ($_->cmndline =~ /login -- mrc/) } @{$proc->
+table};
&killchd($_, 9) foreach @ps;
Ooohhh, Rob no beer function well without!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|