Techblog Index

Don’t be ruthless to your processes

It’s a common (while wrong) practice while administering *NIX/BSD servers (or even stations) to terminate hanged processes with the kill command.

Although the name suggests that it will mercilessly murder the process, its more a signal thrower. Signals tell processes to take determinate actions such as pause, continue, terminate, interrupt current work etc.

Anatomy of process’ death process

There are basically four forms to terminate a process:

Wrong way to terminate a process

Signal 15, SIGTERM. The Terminate Call

Tells your process to end the task cleanly, closing all network connections, file handles, notifying child processes, resetting the terminal and go home in peace. The first thing to do when it becomes unresponsive.

Signal 2, SIGINT. The Interrupt – A slap on the face

Tells your process to stop what it is doing right now and leave immediately. The only way when SIGTERM fails to do the job cleanly. CTRL+C will throw this signal too.

Signal 1, SIGHUP. The Hangup – Kick on the tummy

Quite similar to SIGINT, SIGHUP is one step up. The Hangup is equivalent to the physical medium holding the process going down. It was very common on dial-up lines to indicate that the line had hang-up the call thus terminating the connection.

Signal 9, SIGKILL. The Kill – A bullet on process’ head

SIGKILL will wipe the process out from your tree leaving all the crap it was using. Its the worst way of terminating a process since it will keep your resources open and can lead to any sort of mayhem.

So what to do?

As mentioned on UUK9 (Useless use of Kill -9):

Generally, send 15 (SIGTERM), and wait a second or two, and if that doesn’t
work, send 2 (SIGINT), and if that doesn’t work, send 1 (SIGHUP). If that doesn’t,
REMOVE THE BINARY because the program is badly behaved!

Quite extremist, but totally true!

Treat your processes with dignity, and they won’t betray you! HTH!

 
 

Leave a Reply