Without more details, you may need to kill the parent process. Often, when you fork off a process, the $pid return is actually the bash shell (usually :-) ) , and your actual program is spawned from that. It can get tricky to know exactly which pid you are talking about. See "perldoc Proc::Killfam"..... and here is a manual way. You need to give more info on how you are creating the process, so we can tell if a shell gets involved, and you thus have a parent process.
#!/usr/bin/perl
use warnings;
use strict;
#robau
#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/) } @{$p
+roc->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];
};
| [reply] [d/l] |
You will need to give us a LOT more information in order to be able to help you.
What OS? What process are you trying to kill? By PID? By process name? By user name?
What are "Various conditions"? Which user? | [reply] |
That is possible, since Perl is turing complete and can kill processes. Any Questions?
| [reply] |
"What's the average airspeed velocity of an unladen swallow?"
Oop, wait . . . let me Winnify that . . .
"What's the average airspeed velocity of an unladen swallow? I'm trying to find this with Perl."
Perhaps more germane: Should the OP have read How (Not) To Ask A Question? (I think yes)
| [reply] |
| [reply] |