1752809 Members
6195 Online
108789 Solutions
New Discussion юеВ

Kill command

 
SOLVED
Go to solution
Hill_1
Frequent Contributor

Kill command

Dear all,
I have questions on kill command. When shall we use # kill -9 PID and
# kill PID?

Why we face problem if we # kill -9 automount?

I've gone through the manpage it mentions signal 9 can't be trapped and signal 15 can be trapped. May I know what does it mean?

Thanks in advanced.
Unix
6 REPLIES 6
Uday_S_Ankolekar
Honored Contributor

Re: Kill command

Hi,

Kill -9 is a slaughter and Kill -15 is gracefull Kill.

If kill with other option doesn't work kill -9.

-USA..
Good Luck..
Deepak Extross
Honored Contributor

Re: Kill command

Your process, be it an executable or a simple shell script, can 'trap' or detect signals other than 9. You can setup a 'signal handler' to do stuff on receipt of signals - maybe remove temp files, write a log message, etc. on receipt of a particular signal.
But signal 9 cannot be trapped - as soon as a process gets signal 9, it exits pronto. What is called an 'ungraceful exit'.

see man signal for details.
Michael Tully
Honored Contributor

Re: Kill command

Try to avoid using kill -9

Have a look at the the link below.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,11866,0xf396abe92dabd5118ff10090279cd0f9,00.html
Anyone for a Mutiny ?
A. Clay Stephenson
Acclaimed Contributor

Re: Kill command

Unwise use of kill -9 is one of the most common sys admin errors. Kill -9 should be used as a weapon of last resort. The reason it is bad is that no cleanup is (or can be) done. Temp files are not removed, shared memory, semaphores, and message queques are not removed/detached. In your case those pesky /tmp_mnt entries are left in limbo. If you must kill something, I would do it in this order kill -15, kill -1, kill -2, kill -11, and if and only if you REALLY need to then kill it do you use kill -9. In most cases, kill -11 is almost as sure a kill and does do cleanup.

Clay
If it ain't broke, I can fix that.
Deepak Extross
Honored Contributor
Roger Baptiste
Honored Contributor
Solution

Re: Kill command

<>

Kill sends a signal to the process id specified in the argument.
eg: kill
By default kill sends the signal 15 to the pid.
which is actually kill -15
Signal 15 is a software termination signal which asks the process to terminate gracefully, if possible. That is why you see sometimes, the processes like automount do not get killed by signal 15, since 15 is not a compulsive kill signal.

Some common signals which are defined internally in Unix and used are :
Signal 2 -> Terminal interrupt (control-C)
signal 3 -> create core image and quit
Signal 9 -> kill
Signal 15 -> software termination




Since kill 9 is a definite kill signal to the process, the process tries to terminate immediately but can hang since it could be waiting for I/O to end and does not have control to quit it.

<>

The best analogy can be, if your boss summons, you cannot ignore him and have to respond to it immediately, that makes your boss a Signal 9. Whereas the rest of whom you can ignore or put in the backburner become signal 15 ;-)

Another example:

***
trap 'echo You sent me signal2 but i will not exit hhaaa haaa' 2
while (true)
do
echo 'program running'
done
***

When you run this progam and press control-C
it will give the message -you sent me a signal2-; , but will not exit.
But you cannot do the same to a signal 9. i.e
it cannot be "trapped". It is the boss.

-raj (remembering some old unix lessons).


Take it easy.