Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Killing process in Linux with all child processes. What is the best way?

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

From: <J.Velikanovs_at_alise.lv>
Date: Tue, 25 Jan 2005 00:29:37 +0200
Message-ID: <OF25B842B3.6ECA2606-ONC2256F90.0080D254-C2256F93.007BEF3C@alise.lv>


After short investigation, I have implemented solution below. Seems it’s working (as usually no warranty at all). #!/bin/bash

# Before call the routine which possible can hung lets run the killer.sh
# specifying time out 30 sec and our process pid $$
/usr/bin/nohup ./killer.sh $$ 30 1>/dev/null 2>&1 &
# Lets run the routine which can hang

./my_possible_hanhing_script.sh

killer.sh
#!/bin/bash

# Check if $1 process finished within timeout then exit else got to
killing

# Killing

v_pforkill_tmp=`pstree -p $1`
v_pforkill=`echo $v_pforkill_tmp |
awk -F"-" '{NF>0;for (i=1;i<=NF;i++) print $i}' | awk -F")" '{print $1}' |

grep -v killer.sh |
grep -v pstree |
sort -u |

awk -F"(" '{print $2}' |
awk '{ORS=" "; print $1 }'`

kill -9 $v_pforkill

Jurijs
+371 9268222 (+2 GMT)



Thank you for teaching me.
http://otn.oracle.com/ocm/jvelikanovs.html

J.Velikanovs_at_alise.lv
Sent by: oracle-l-bounce_at_freelists.org
2005.01.22 00:25
Please respond to J.Velikanovs  

        To:     J.Velikanovs_at_alise.lv
        cc:     oracle-l_at_freelists.org, oracle-l-bounce_at_freelists.org
        Subject:        Re: Killing process in Linux with all child 
processes. What is the best way?

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_at_alise.lv
Sent by: oracle-l-bounce_at_freelists.org
2005.01.21 22:34
Please respond to J.Velikanovs  

        To:     oracle-l_at_freelists.org
        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
--
http://www.freelists.org/webpage/oracle-l


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


--
http://www.freelists.org/webpage/oracle-l
Received on Mon Jan 24 2005 - 17:36:19 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US