kill process with care

November 18th, 2006 mysurface Posted in Common, kill, killall, pkill, sudo | Hits: 166446 | 20 Comments »

A lots of people likes to do kill -9, which means kill a process by force. By specified -9, process will be terminated by force, which is very fast and confirm kill but it leaves hidden side effects. Refers to Useless use of kill -9, kill a process by specified -9 may leave child processes of a parent orphaned, temporary files open, shared memory segments active, and sockets busy. This leaves the system in a messy state, and could lead to unanticipated and hard to debug problems.

How to kill a process?
To kill a process, you need to know its process ID (PID). The easiest way to check is by ps with grep, let say I wanna check the PID of gaim.

ps aux | grep gaim

Let say it returns PID with numbers 5678, Then now you can kill and check with ps and grep again to confirm whether the process have successfully kill.

kill 5678

Alternatively, you can kill processes by specified process name using pkill, again I wanna kill gaim.

pkill gaim

How to force kill a process?

You can choose a signal to send to the process, checks the kill manual for available signals to send.

man kill

Usually if you process was unable to kill, first check whether you need to have root privilege to kill? certain process is instantiate by root, to kill you must have the same level of privilege.

sudo kill 5678

Second, try to kill with -1 and -2 before uses -9.

kill -1 5678

Okay, the process is really irritating, let me force kill it,

kill -9 5678

Some process may have multiple instances, killing the process one by one with PID is nightmare, so kill them all one shot!

killall gaim

Still there? grrrrrrrrrr!

sudo killall -9 gaim

Haha this is just an example, anyway you usually no need to perform a force kill like that.

20 Responses to “kill process with care”

  1. lol dat was funny
    you can also use
    sudo kill -KILL pid

  2. [...] As intoduce in this post, you can kill any process with its PID. But what if you want kill a GUI-based program? You can use this: [...]

  3. [...] Core dump will be generated automatically if a program crashed due to segmentation fault or some other reason. But core dump will not be generated if an application halt and been terminate by control+c or conventional way of kill or pkill. Therefore, how we are going to investigate the reason of the halt process? There is an option that you can gdb a current running process by specified the GID. But what if you are not the author of the program? You are just a support engineer who wants to escalate the bugs to development team by providing the core file, what can you do? [...]

  4. believe me or not, i ran into a strange problem on ubuntu 8: put in a scratched CD, refused to read it. tryied to open a text file, processor load 100%, CD cannot be ejected or unmounted, killall -9 gedit has no effect, and even afeter removing the CD by force from drive, the process is still there with 100% load..

  5. Can any one help me how to kill process by reading the process id from file

  6. Can any help how to connect dialup internert to ubuntu 8.10

  7. Missed period

  8. Hi, I am not able to see your site correctly inside of Chrome browser, I am hoping you can look into fixing this.

  9. Cosy to run out of methods that undoubtedly affair, appreciation again!

  10. Spot on with this write-up, I really assume this web site needs much more consideration. I’ll most likely be again to learn rather more, thanks for that info.

  11. Hey there webmaster! This might be an unusual way to contact you, but I assure you that you’ll want to hear what I have to say. I’ve been doing internet search engine ranking optimization for years now, and I’m constantly searching for better ways to help my wordpress clients. I’ve recently had a breakthrough in developing such a tool – and I can guarantee you that this tool will make you rank higher in Google for whatever keyword you want.. within days! Check it out here through this comment’s link. Good luck to you and I wish you success for your future endeavours!

  12. The following is something that should be read by everyone. I wouldn’t blame you if you were to turn and run as soon as you hear the word ‘free’ mentioned. However, this is something that I am sharing because I already know how it works. Companies give stuff away all the time and this site just has all these offers in one place and makes it easy for you to take advantage of each offer. You can just search through all the free offers by category until you find something that interests you or you can just take advantage of each and every offer. What keeps the site going is the memberships but you don’t have to become a member. You can go the free route on that one as well. As a free member, you can still get the 5 latest free offers each week, at zero cost to you. You don’t have to jump through any hoops in order to take advantage of the free offers. Of course, for each free offer that you want to take advantage of, you need to fill in your name and address so that they can ship the stuff to you. Also, and this might be the best part, if you actually pay the $25 to be a member, you can market this stuff to the world and make money giving away free stuff! As a paying member, you also get instant access to thousands of free offers, you’re automatically entered into the payout matrix and much more. The business plan ($25) gives you access to the video mailer that you can use for your free stuff business as well as any other business you have, business cards and other promotional tools. Just give it a look and let me know what you think.

  13. Thanks very good for report, I follow your blog

  14. I do agree with all the ideas you’ve introduced on your post. They’re really convincing and will definitely work. Nonetheless, the posts are very quick for starters. Could you please lengthen them a little from subsequent time? Thank you for the post.

  15. Lise Mcmanis Says:

    Asus is coming out with accessories for the Eee Pad Transformer, including a Mini HDMI to VGA cable. Though in the meantime you could get a HDMI to VGA converter as a inter-rum solution.

  16. 321658 221809I don?t normally look at these types of internet sites (I?m a pretty modest person) – but even though I was a bit shocked as I was reading, I was surely a bit excited as effectively. Thanks for producing my day 953237

  17. 601040 75603There is noticeably a lot to know about this. I believe you made some nice points in features also. 436480

  18. 516429 609964Awesome weblog, I?m going to spend far more time researching this subject 296277

  19. I visited several—-sites—-except—-the audio feature—-for audio songs present—-at this web page—-is really—-superb—-louis vuitton outlet online, Chanel bag.html

  20. I needed more information on (an web postal service)
    so I signed up for the free 30 day trial on Could 3rd.

Leave a Reply