« GFK's, what about that nickname? | Main | Généalogie »

novembre 12, 2004

How to kill a unix process

Were you ever told to kill a Unix process using "kill -9 pid"? Did you know that that was wrong? Here's a copy of a Usenet posting by Randal L. Schwartz explaining why.

I keep a printed copy of the message posted on the wall.

Newsgroup:comp.unix.questions
Date:2001-01-20 (20 Jan 2001 09:58:20 -0800)
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Dangerous use of Kill -9 (was Re: kill users script?)

>>>>> "dipwad" == dipwad writes:

dipwad> kill -9 $PID
...

dipwad> Maybe this will get you started in the direction you wish to take.

Only if you want to make a script which has many unintended consequences.

As I've said before...

No no no. Don't use kill -9.

It doesn't give the process a chance to cleanly:

1) release IPC resources (shared memory, semaphores, message queues)

2) clean up temp files

3) inform its children that it is going away

4) reset its terminal characteristics

and so on and so on and so on.

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!

Don't use kill -9. Don't bring out the combine harvester just to tidy
up the flower pot.

Just another Useless Use of Usenet,
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Posted by gfk at novembre 12, 2004 6:34 PM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?