Kill process tree by parent process PID

Method 1 :

First you need to find the parent process using ps command,

ps -aef | grep -v grep | grep <PROCESS_NAME> | awk {‘print $3′}

usually the lowest process ID would be the parent.
Now after finding the parent process ID, its time to kill all ;)

Syntax : kill -TERM -<PARENT PID>
E.g : kill -TERM -24278

Method 2 :

Using ps command check the process’s by name :

Syntax : ps -aef | grep -v grep | grep <PROCESS_NAME> | awk {‘print $9′}
E.g : ps -aef | grep -v grep | grep test.pl | awk {‘print $9′}
now its time to kill them all :

Syntax : ps -aef | grep -v grep | grep <PROCESS_NAME> | awk {‘print $2′} | xargs kill -9
E.g : ps -aef | grep -v grep | grep test.pl | awk {‘print $2′} | xargs kill -9

Note : The grep -v grep should be used to exclude the grep command being listed in the grep result.

Caution : Also note that the above commands should be executed with extreme caution,as they may cause system failure if not properly used or if executed under root user.

  

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">