Unix provides different commands in order to kill processes. Actually, Unix is the predecessor of the Linux distributions like Ubuntu, Debian, Mint, RHEL, CentOS, etc., and provides the same commands to kill processes. The Linux distributions are copied commands from Unix and also added some new commands to kill processes.
List Processes
For Unix, before killing the process with different tools we should list the running processes and get information like Process ID or Process Name. The ps aux
command can be used to list running processes with information like user, process ID, CPU usage, and process command.
$ ps aux
The grep command can be used to filter running processes according to their name, binary, or path. In the following example, we filter gnome-related processes.
$ ps aux | grep gnome
Kill Process with kill Command
The kill
command is the first and standard command to kill the process in Unix. The kill command accepts the Process ID.
$ kill 1550
If the process is owned by another or, a root user the sudo
should be used to kill this process like below.
$ sudo kill 1550
Kill Process with pkill Command
The pkill is an alternative command for the killing process. The pkill command accepts the process name or command name to kill. In the following example, we kill the process whose name contains gnome
.
$ pkill gnome
With root privileges use the sudo like below.
$ sudo pkill gnome
Kill Process with killall Command
The killall
command is very similar to the pkill and used the same way to kill all processes for the specified name.
$ killall gnome