Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

kill or kill -9

Status
Not open for further replies.

dman7777777

IS-IT--Management
Jan 13, 2007
52
US
At work we had to shut down a process that was stuck/hanging. I wanted to do a kill -9 while others argued that a hard stop is bad and a kill is better. I think otherwise, if the process is hanging then it is already corrupted and there is no real chance of it recovering itself or 'finishing' what it is doing. So, if you want a process to stop then use a kill -9 to make it stop with no chances of it not fully stopping. Am I right or wrong?
 
kill -9 is the last solution to a hang process.

The reason why it is recommended to use kill alone (ie without -9) is that it will do the cleaning up of whatever that process was doing (for example to close open files by this process and to stop any dependent or child processes of that process).

Regards,
Khalid
 

if kill is issued with no signal argument, it defaults to TERM signal. As it is maskable, the process itself fas the possibility to arrange some final steps before exiting (you can use this facility even in a shell script, using trap)

Alhoug the process seems to be hung, it may be in a normal state, in the point of vview of the OS. Executing an endless loop for example.

When TERM signal is delivered to the process, it may have a singnal handler attached to it, and the the processes signal handler will be given control, to stop the process in its own favor. Flushing buffers to open files, close them, etc...

KILL signal ( -9 or -KILL ) is not maskable, the process can not have any handler on it. The footprint of the process is just vanished out of the memory and kernel structures, along with its child processes.

So I suggest the following sequence
kill -TERM <PID>
sleep some time
check if process exists yet
if it does, then kill -KILL <PID>

--Trifo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top