>Hi,
> I have a problem in killing all the processes under a process.
> When I try to kill a Parent process, Child process and its
> child process are not being killed. I do manually by checking
> 'ps -ef |grep process' and then kill each process and its child
> process individually. It some times consumes lot of time for me
> and also sometimes I will be missing some sub-processes.
If the processes are all part members of a single process group, you can
use the negative of the process group ID to send a signal to all the
processes in the group at once. Generally, the PGID will be the PID of the
parent process that heads the group.
If that doesn't do what you want, here's a perl script that figures out the
process hierarchy and then kills all the processes destined from a given
process.
#!/usr/local/bin/perl -w
$signal = $ARGV[0];
$top_process = $ARGV[1];
%children = ();
open PROCESSES, "ps -eaf |" || die "$0: open ps: $!\n";
while (<PROCESSES>) {
next if /^ +UID/; # Skip heading
my ($pid, $ppid) = /^\s*\S+\s+(\d+)\s+(\d+)/;
Quote:}
kill $signal, $top_process;
&killchildren($top_process, $signal);
sub killchildren {
Quote:}
--
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.