How to Kill Process and Its sub-process and its sub-process??

How to Kill Process and Its sub-process and its sub-process??

Post by Sai Chimakur » Sat, 12 Jun 1999 04:00:00



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.

        Can  any one help me in issueing a shell command or writing a
        shell script.

        Thank you all in advance for your time.

Thanks & Regards,

*******************************************************************

 
 
 

How to Kill Process and Its sub-process and its sub-process??

Post by Barry Margoli » Sat, 12 Jun 1999 04:00:00




>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.

 
 
 

1. How to Kill a process and its sub-process and its sub-process at a time..

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.

        Can  any one help me in issueing a shell command or writing a
        shell script.

        Thank you all in advance for your time.

Thanks & Regards,

*******************************************************************

2. recommended reading

3. Help: kill sub-process after parent killed

4. Attention ISAPNP Guru's.....

5. Sub-sub-sub-sub-sub subdomains?

6. Problems with Suspend To Ram/S3/STR (Msi Kt-880 Delta)

7. waiting on a sub-sub process

8. Writting programs to access bbs from unix?

9. Killing Sub-Processes?

10. Kill sub-processes

11. How can kill all child processes without killing parent process ?

12. I/O to sub processes - HELP

13. Can Apache spawn a sub process to run as a different user?