Copyright November 2003 Tony Lawrence
A better way to kill processes is to send a hangup (kill -1) or a sigterm (kill -15). Any process has the option of catching such signals and doing any final housekeeping tasks before dieing. The process can also choose to ignore you, so you may ultimately need a -9 anyway, but at least you gave it a chance to die gracefully.
The problem is that "-9" is an absolute kill - any process that receives that signal has to die immediately: no chance to clean up anything it might be doing, write out its file buffers or anything else: just die, right now.
By the way, the "receives" in that "any process that receives that signal" is very important. A process that is sleeping down in a driver doesn't get the signal until the kernel wakes it up. That's why some processes seem unkillable:
Kill isn't always about killing. Many processes uses signals ("signal" would have been a better name for "kill") to alert them to needed actions. "kill -1" often causes a process to re-read its configuration files, for example.
Many shells allow a "kill -0" to check if a process still exists. This can be useful where "wait" isn't what you want or where your shell didn't start the process you want to monitor. You can use that to kill off a process that might hang:
# spin off something that might hang: myprog & THAT=$! sleep 300 kill -0 $THAT && echo "still running"
Linux "killall" is a useful program. You can "killall httpd" to kill of all running httpd processes. But watch out: some systems (SCO) have a similarly named command that has much more drastic consequences: see SCO killall.

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.
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.
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.
Click here to add your comments
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