How to Kill Process in Linux

This post will guide you how to kill or terminate a process in Linux operating systems. How do I use kill command to stop Process in Linux or Unix system.

kill process in linux1

Kill Process by PID


If you want to kill a running process by PID from the command line in your Linux system, and you can use kill command. And the syntax is as below:

$ sudo kill PID
$ sudo kill -9 PID
$ sudo kill -SIGTERM PID

For example, you wish to kill a running process called “mysql”, and you need to find the process ID with pgrep or ps command, and then kill it with kill command. Type:

$ pgrep mysql

Or

$ ps aux | grep mysql

Outputs:

devops@devops:~$ pgrep mysql
5376

devops@devops:~$ ps aux | grep mysql
mysql 5376 1.9 17.8 1157388 179692 ? Sl 02:41 0:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
devops 5413 0.0 0.1 21532 1156 pts/3 S+ 02:42 0:00 grep --color=auto mysql

From the above outputs, you would notice that the process ID of mysql is 5376.
To kill mysql process, type one of the following commands:

$ kill 5376

Or

$ kill -9 5376

Kill Process by Process Name


If you want to kill process by process name, and you can use pkill command. The syntax is:

$ sudo pkill processName
$ sudo pkill mysql

Kill two or More Processes by PIDs


If you want to two or more processes by PID in a single command, and you can use the kill command, the syntax is:

$ kill pid1 pid2

Or

$ kill -9 pid1 pid2

Kill Processes Using Killall command


If you want to kill any process matching a given string or process name, and you can use killall command. For example, you wish to terminate the process named “mysql”, just type the following command:

$ sudo killall mysql

If you want to get more further information about those commands, and you can see man pages with the following commands:

$ man kill
$ man pkill
$ man killall
$ man pgrep

Conclusion


You should know that how to kill or terminate a running process in CentOS or RHEL Or Ubuntu Linux systems with kill/pkill/killall commands.

You might also like:

Sidebar



back to top