Live Chat!

kill process with care

* * * * * 1 votos

November 18th, 2006 mysurface Posted in Common, kill, killall, pkill, sudo | Hits: 23663 |

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.

3 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? [...]

Leave a Reply