How to Kill Linux Server Processes

Linux is highly stable, amazingly secure, and completely free, but even a remarkable OS like Linux has its bad days. Fortunately, when things go wrong with a Linux server, it is usually pretty easy to get things back on track. Rather than rebooting your whole server, which would disrupt service to your users or customers, an effective way to deal with problem applications is to kill their processes.

A process is an individual entity running in the memory, and some applications may have multiple processes running at once. Apache HTTP Server, for example, may have several child processes associated with each virtual server. In some cases, restarting a memory resident service is the best course to take to get the server running smoothly again. In other cases, you may only need to kill individual runaway processes.

The command to kill a process is “kill”, but in order to kill it, you need to know the PID (process identifier), which is a unique number associated with that process. To find out any process’ ID, run the “ps” command:

ps aux

This will list all processes and the PID’s associated with each. Once you know the PID (let’s say its 24523, for example), you can kill it from the command line:

kill 24523

In some cases, you may want to kill all processes associated with a specific command. To do this, run “killall” from the command line:

killall commandname

Keep in mind that not all processes are run by the same user, and you may need to have root access to kill certain applications. Furthermore, there is a chance that a process simply will not die (i.e. Jason Bourne processes). In those situations, you can escalate the kill order.

First, try “kill pid” again, then try in this order:

kill -INT pid
kill -INT pid (again)
kill -KILL (or kill -9)

The “SIGKILL” (kill -9) signal is one that the process will not ignore under any normal circumstances. You should use it with caution, however, because some programs need cleanup before they exit, but if nothing else works, the kill signal may be necessary. If it still will not die, you need to investigate more to find out why the application is stuck.











Comments: