Linux is a process bound operating system where every taks and action is taken via processes. There are a lot of process for system and user related tasks. Daemons or service processes expected to be run in background continuously and user processes generally started and completed after complating tasks. But in some cases we may need to kill or end or stop a process in Linux.
Reasons To Kill Linux Process
Linux users or administrators have different reasons to kill a process. Below we list some of the most common reasons to kill linux process.
- The process stucks and does not responds.
- The process entered into endless loop.
- The task does not required to be completed by the process.
- Another process is started with the related task.
List Running Processes
Generally in order to kill a process in Linux the process name or process ID should be known and provided to the command which will kill the process. The processes can be listed with different commands but one of the most popular command to list running processes is the
top command. The top command provides
ps aux command can be used to list processes with their process ID and related information.
$ ps aux
In some cases we may look specific process with its name or command. The
pgrep command can be used to grep or filter processes according to their name or process ID. In the following we filter the process with its name which is bash .
$ pgrep bash
The process ID is pritend as output of the pgrep command.
Kill Process with kill Command
The native and popular command to kill a process is
kill command. The processes are controlled and killed by using signals and the kill command sends the
SIGTERM signal by default. The sigterm means
signal termination . The process ID is provided to the kill command.
$ kill 1234
The SIGTERM is provides more policy termination of the process. The
SIGKILL is more harsh way to kill a process which can be used with the kill command. The last resort to kill a process or daemon is killing it with the
$ kill -SIGKILL 1234
-9 option can be used.
$ kill -9 1234
Kill Process with pkill Command
pkill command can be also used like a grep. The pkill command use the process name in order to kill it.
$ pkill bash
Kill Process with killall Command
killall command can be used to send kill signal to the all processes which matches with the specified process name. The process name or ID is provided is killed. In the following example we kill all process which name contains
$ killall bash
Kill process with exact name can be accomplished by using the killall command with the
$ killall -e bash
By default killall command is case sensitive where uppercase and lowercase letters are treated as different but
-I can be used it caseinsensitive which will ignore case for the process name.
$ killall -I bash
Ask for confirmation to kill process can be done with the
-i option for the killall command.
$ killall -i bash