search on lynty.com

Related Articles

kill

Print PDF

 

### KILL THE PROCESS ###


Kill are of two types:

1.Graceful Kill

kill -15 pid

2.Forcible Kill

Kill -9 pid

Kill pid. This format wont work.. Just check it..

These kill differs in releasing resources forcibly or gracefully

The best practices  
source:
http://www.linuxquestions.org/questions/linux-software-2/killing-a-process-fails.-have-tried-all-i-know.-364533/

Gradually increase the strength of your kill signals rather than going in there with the sledge hammer straight away i.e. go for kill, -3, -1, -11 (beware this will often produce a core dump), -5 and then if all that fails go for the -9. You should make sure the process is given an adequate amount of time to exit and clear up after itself before wading in with the old -9 though.

It is actually a nice idea to write a bit of a wrapper script to an alias kill to it instead of using /usr/bin/kill just to automate the process a bit. Something like this might do the trick...

#!/bin/bash

if [ $1 = "-9" ]
then
echo "Kill signal of -9 is not acceptable. Overriding."
shift
fi

for PID in $*
do
PROCESS=`ps -fp$PID | grep -v STIME`
USERID=`echo $PROCESS | awk '{print $1}'`
PROCNAME=`echo $PROCESS | awk '{print $8}'`

LIVE=`ps -fp$PID | grep -c -v STIME`
if [ $LIVE -gt 0 ]
then
echo "Killing process $PID $PROCNAME for $USERID with default signal."
/bin/kill -15 $PID
sleep 2
LIVE=0
fi
LIVE=`ps -fp$PID | grep -c -v STIME`
if [ $LIVE -gt 0 ]
then
echo "Process still alive. Upping kill signal to -3"
/bin/kill -3 $PID
sleep 2
LIVE=0
fi
LIVE=`ps -fp$PID | grep -c -v STIME`
if [ $LIVE -gt "0" ]
then
echo "Process still alive. Upping kill signal to -1"
/bin/kill -1 $PID
sleep 2
LIVE=0
fi
LIVE=`ps -fp$PID | grep -c -v STIME`
if [ $LIVE -gt "0" ]
then
echo "Process still alive. Upping kill signal to -11"
/bin/kill -11 $PID
sleep 2
LIVE=0
fi
LIVE=`ps -fp$PID | grep -c -v STIME`
if [ $LIVE -gt "0" ]
then
echo "Process still alive. Upping kill signal to -5"
/bin/kill -5 $PID
sleep 2
LIVE=0
fi
LIVE=`ps -fp$PID | grep -c -v STIME`
if [ $LIVE -gt "0" ]
then
echo "Unable to kill process."
LIVE=0
fi
echo ""
done
 

Related Articles+