APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> (SCO Unix) When should I use kill -9?


SCO Unix, Xenix and ODT General FAQ

This article is from a FAQ concerning SCO operating systems. While some of the information may be applicable to any OS, or any Unix or Linux OS, it may be specific to SCO Xenix, Open Desktop or Openserver.

There is lots of Linux, Mac OS X and general Unix info elsewhere on this site: Search this site is the best way to find anything.

When should I use kill -9?



When you can't kill it with -15.

The idea here is that properly written programs will respond to a -15 by cleaning up anything they need to do before dying. Understand that this is not a matter of priorities, or the system giving more time with a -15; it's simply that a program can catch the -15, do what it needs to do and then voluntarily exit. It could also choose to ignore the -15 all together. If it hasn't made any provisions at all, the -15 works exactly like the -9: the process dies immediately.

A "kill -9" just causes the process to die; it gets no chance to do any cleanup. Therefore, if you don't know how a program was written, you should try the -15 first, in case it does need to clean up files, flush logs or whatever. If the -15 doesn't work, then use the -9.

It's the unfortunate choice of the word "kill" for this command that has caused all this confusion. It should have been called "signal", because that's what it really does- it sends a signal to a process. It's no different than you waving at someone to get their attention or tapping them on the shoulder.

What the process does when signal taps it on the shoulder depends. Many signals have the default action of causing the process to die. That's the default, but the programmer can choose to write the code differently.

A process can choose to ignore signals (with exceptions) or to catch them and take some other action. You've probably used "kill -1" to restart inittab or something else before. There's nothing magic about signal 1; it's just that those processes have arranged to pay attention to that and re-read or restart when they get it. Some other process could interpret a -1 in a different way- that's up to whoever wrote the code.

The shell "trap" command handles signals. You might have used this to ignore interrupt for certain scripts.

trap "" 2
 

says "if you get a 2, ignore it"

trap 'echo nope!' 2
 

By the way, to reset all that, just do "trap 2".

causes the "nope!" to be echoed when you interrupt.

Every process has a default action. You can get a listing of those actions with "man 7 signal" (Linux) or "man signal" (SCO).

A "kill -9" cannot be ignored or trapped. If a process sees signal 9, it has no choice but to die. It can't do anything else- not even gracefully clean up its files.

A -15 (which is the same as just doing a kill without minus anything) is a signal with the default action of killing the process. However, it can be caught (that's the technical term for not ignoring) or ignored. Typically, a process that does arrange to catch a 15 will clean up open files, do whatever else it needs to, and then die.

That's why it is a good idea to just try an ordinary kill first. There are three possible outcomes:

  • The process has done nothing to prepare for this and will immediately die.
  • The process will write its buffers, close its files etc. and then die. What it does is up to the programmer.
  • The process will ignore the signal and you'll have to send a -9 to get rid of it.

See also Why can't I kill a process with -9?




If this page was useful to you, please help others find it:  





6 comments



Click here to add your comments
- no registration needed!




Wed Apr 19 19:45:59 2006: 1940   anonymous


This answered my question very quickly! Thanks!



Mon Mar 29 17:57:17 2010: 8299   RadioCat

gravatar


"It's no different than you waving at someone to get their attention" No different? It only imparts the ability to shoot them in the head, as well as tap them on the shoulder. The kill name is a misnomer, but a fortunate one, else Monzy's "Kill Dash Nine" would be pretty meaningless. http://graphics.stanford.edu/~monzy/KillDashNine.mp3



Mon Mar 29 18:12:03 2010: 8300   TonyLawrence

gravatar


I really dislike rap, so it IS meaningless to me :-)



Sun Sep 26 02:31:48 2010: 9008   KB1JWQ
http://serverwrangler.com
gravatar


Technically a process never sees a SIGKILL or a SIGSTOP; they (like all signals) go to the kernel, which in turn either passes them onto the process for handling, or (in the case of the two I just mentioned) actions them directly. The reason STOP and KILL are untrappable is that the process never sees it at all.



Sun Sep 26 12:13:19 2010: 9009   TonyLawrence

gravatar


I would have thought I had said that here, but you are correct, I did not and worse, I said "if a process sees -9" - it never sees anything, the kernel sees it and kills the process as you say.

This article is very old - I'm surprised none noticed that before now.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

g_face.jpg

This post tagged:

       - FAQ
       - Unix Kill















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)