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

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

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 a process and its sub-process and its sub-process at a time..

Post by Ken Pizzi » Sun, 13 Jun 1999 04:00:00



Quote:>    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 parent process is a process group leader, then this
is simple --- merely preceed its PID with a - and the whole
process group gets the signal:
   kill -TERM -$pid

If it isn't a process group leader, and you have some control
over how the process family gets started, I'd suggest forcing
it to be the leader of a new process group.  But if you can't
do that, then you'll have to resort to building a model of
the process tree and use that.  I suppose the easiest would
be to use perl:
  #! /usr/bin/perl
  open(STDIN, "ps -ef |") || die "cannot start ps: $!\n";
  while (<STDIN>) {
    ($junk, $pid, $ppid) = split;

  }


    my $pid = shift;


  }

(Note that you might need to make changes to adapt this script
to the implementation of ps on your system.  For instance, you
might need to use "ps ax" instead of "ps -ef", and use additional
"junk" variables on the "split" assignment.)

If that were placed in a script in your $PATH named "killtree",
it could be used as follows:
   killtree $parentpid

                --Ken Pizzini

 
 
 

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

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. Help: S3-968

3. Help: kill sub-process after parent killed

4. rwho don't works

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

6. How to update to Airport Support?

7. waiting on a sub-sub process

8. a mailing list box

9. Killing Sub-Processes?

10. Kill sub-processes

11. Many sub process at same time in Ksh ?

12. Find exact creation time of a process; not kill a wrong process

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