Re: Killing process in Linux with all child processes. What is the best way?

  • From: J.Velikanovs@xxxxxxxx
  • To: J.Velikanovs@xxxxxxxx
  • Date: Sat, 22 Jan 2005 00:25:51 +0200

Thank you all who pointed me on pkill/pgrep.
One little inconvenience, which these can?t handle: it is subcalls.
Lets say my script calling other script and so on.
For example I have process hierarchy like below 
|-sshd,754) 
      |-sshd,25317) 
          `-bash,25547) 
              `-su,25597) - cacti 
                  `-bash,25598) 
                      |-pstree,28688) -ap 
                      `-sh,28946) ./cron_test.sh 
                          `-sleep,27900) 20

I would like to kill all those processes.
If I run pkill ?P 754, just two processes going to be killed (754, 25317).

Is there better chance to kill them, except I have posted?

Jurijs
+371 9268222 (+2 GMT)
============================================
Thank you for teaching me.
http://otn.oracle.com/ocm/jvelikanovs.html






J.Velikanovs@xxxxxxxx
Sent by: oracle-l-bounce@xxxxxxxxxxxxx
2005.01.21 22:34
Please respond to J.Velikanovs
 
        To:     oracle-l@xxxxxxxxxxxxx
        cc: 
        Subject:        Killing process in Linux with all child processes. 
What is the best way?


Hi ALL,
Looks like off topic, but it can be useful for Oracle administration 
purposes on Linux (Unix) platform.

I have need to kill one of my shell scripts in case of timeout is off.
Not just single process but all that is relative to it.

After searching thought net I have wrote my routine.
Looks like there is place for improvement. Can somebody recommend one, or 
somebody has more elegant way how to achieve the goal.

#!/bin/bash
# there $1 is pid of the process 
v_pforkill=`pstree -p $1 |
awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' |
sort -u |
awk -F"(" '{print $2}' |
awk -F")" '{print $1}' |
sort -u  |
awk '{ORS=" "; print $1 }'`
kill -9 $v_pforkill

With all my respects,
Jurijs
+371 9268222 (+2 GMT)
============================================
Thank you for teaching me.
http://otn.oracle.com/ocm/jvelikanovs.html



--
//www.freelists.org/webpage/oracle-l


--
//www.freelists.org/webpage/oracle-l

Other related posts: