1847901 Members
3382 Online
104021 Solutions
New Discussion

kill command

 
SOLVED
Go to solution
Shivkumar
Super Advisor

kill command

Dear Sirs,

While killing a process as a root the command "$kill pid" is preferable or "kill -9 pid" preferable ?

Thanks,
Shiv
20 REPLIES 20
Nguyen Anh Tien
Honored Contributor

Re: kill command

#kill -9 pid is prefer
tienna
HP is simple
Senthil Prabu.S_1
Trusted Contributor

Re: kill command

Hi,
kill -9 is preferred always,
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Vibhor Kumar Agarwal
Esteemed Contributor

Re: kill command

Kill -9 is used for force killing.

So it depends on your situation.
You might kill an vital process with kill -9.

Otherwise you know hte answer.
Vibhor Kumar Agarwal
Arunvijai_4
Honored Contributor

Re: kill command

Hi Shiv,

# kill -9 will immediately kills the process and sometimes it is prefered.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Senthil Prabu.S_1
Trusted Contributor
Solution

Re: kill command

Shiva,
sometime, -9 does have negative impact. The KILL signal does not allow a process to run any cleanup code, which means blasting away with kill -9 may leave child processes of a parent orphaned, temporary files open, shared memory segments active, and sockets busy. This leaves the system in a messy state, and could lead to unanticipated and hard to debug problems.


One man's "magic" is another man's engineering. "Supernatural" is a null word.
Joseph Loo
Honored Contributor

Re: kill command

hi,

try "kill pid" first, if do not succeed, use "kill -9". but make sure u get the correct pid.

regards.
what you do not see does not mean you should not believe
Senthil Prabu.S_1
Trusted Contributor

Re: kill command

Hi,
It depend on your need to use -9 with kill command.

Also, refer this link which talks that -9 option in other way;
http://www.speculation.org/garrick/kill-9.html
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Arunvijai_4
Honored Contributor

Re: kill command

Hi Shiv, You can refer this link for kill -9

http://sial.org/howto/shell/kill-9/

The KILL signal does not allow a process to run any cleanup code, which means blasting away with kill -9 may leave child processes of a parent orphaned, temporary files open, shared memory segments active, and sockets busy.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Senthil Prabu.S_1
Trusted Contributor

Re: kill command

Hi again,
THe situation when it is preferred to use kill -9 is
"Use of kill -9 by default may seem acceptable where a known problematic application is involved. However, using the KILL signal by default assumes the problematic process will remain so."
One man's "magic" is another man's engineering. "Supernatural" is a null word.
A. Clay Stephenson
Acclaimed Contributor

Re: kill command

Kill -9 pid should be used as a weapon of last resort. It you do a man signal, you will find that SIGKILL (9) cannot be ignored or caught. This means that it is not possible to do any cleanup (e.g. remove temp files, shared memory, semaphores, etc.)

The best approach is to start to kill in this order: -15, -1, -2, -3, -11, and finally and only if it's really necessary a kill -9. You should test for the existence of a process via kill -0 pid between each of these escalating signal. kill -0 pid sets $? to 0 if the PID is still valid.

kill -9 pid is one of those bad techniques that many admins learn but is almost always a bad idea.
If it ain't broke, I can fix that.
Arunvijai_4
Honored Contributor

Re: kill command

Hi Shiv, As from man page of kill, you will get to know what happnes with various signals.

signum signame Name Description
___________________________________________________________________________
0 SIGNULL Null Check access to pid
1 SIGHUP Hangup Terminate; can be trapped
2 SIGINT Interrupt Terminate; can be trapped
3 SIGQUIT Quit Terminate with core dump; can be trapped
9 SIGKILL Kill Forced termination; cannot be trapped
15 SIGTERM Terminate Terminate; can be trapped
24 SIGSTOP Stop Pause the process; cannot be trapped
25 SIGTSTP Terminal stop Pause the process; can be trapped
26 SIGCONT Continue Run a stopped process

As Clay said, "-9" is the last weapon.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Devender Khatana
Honored Contributor

Re: kill command

Hi Shiv,

As indicated earlier kill -9 should be used at last when other does not seems to work.Sometime even you will find that not even kill -9 works, this will be generally the case when some process has some pending I/O and that is not getting competed due to some failure.

But these sort of scenarios are very rare.

HTH,
Devender
Impossible itself mentions "I m possible"
Shivkumar
Super Advisor

Re: kill command

Hi Clay,

While using man signal command how to go to directly to the page SIGKILL (9) ?

currently i go by each line and page until i reach there.

Regards,
Shiv
Arturo Galbiati
Esteemed Contributor

Re: kill command

Hi Shiv,
best way is to kill pid to gracefully release all the resources busy by the pid, while for a while and if it's not die kill -9 pid.
HTH,
Art
Raj D.
Honored Contributor

Re: kill command

Shiv ,

First try gracefully

i.e
# kill -1 PID

similar to
# kill -HUP PID



If it is not killed gracefully , try killing with SIGKILL signal i.e
# kill -9 PID.


------------------------------------
Here are the detail Signals for kill :

1) HUP 16) USR1 31) RESERVED
2) INT 17) USR2 32) DIL
3) QUIT 18) CHLD 33) XCPU
4) ILL 19) PWR 34) XFSZ
5) TRAP 20) VTALRM 35) bad trap
6) IOT 21) PROF 36) bad trap
7) EMT 22) POLL 37) RTMIN
8) FPE 23) WINCH 38) RTMIN+1
9) KILL 24) STOP 39) RTMIN+2
10) BUS 25) TSTP 40) RTMIN+3
11) SEGV 26) CONT 41) RTMAX-3
12) SYS 27) TTIN 42) RTMAX-2
13) PIPE 28) TTOU 43) RTMAX-1
14) ALRM 29) URG 44) RTMAX
15) TERM 30) LOST
-----------------------------------------



Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Arunvijai_4
Honored Contributor

Re: kill command

Hi Shiv, # man kill and /SIGKILL will reach you to kill -9.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Shivkumar
Super Advisor

Re: kill command

"kill pid" uses which signal number by default ?
Arunvijai_4
Honored Contributor

Re: kill command

Hi Shiv, kill send SIGTERM (15), the (default) terminate signal.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Devender Khatana
Honored Contributor

Re: kill command

Hi,

Kill by default uses signal 15. This will be the same when you do not define any signal.

HTH,
Devender
Impossible itself mentions "I m possible"
Raj D.
Honored Contributor

Re: kill command

Shiv ,

15 is the default, if you do not specify any signal , 15 is TERM , i.e SIGTERM


hth,
Raj.
---
" If u think u can , If u think u cannot , - You are always Right . "