How To Kill Processes using Kill, killall and Pkill in Linux

This post will guide you how to kill a process using kill, killall or pkill command from the command line in your Linux system. How do I find out the ID of a running process in Linux.

kill-process-pkill1

List All Running Processes


You can use “ps” command to list all the running processes on your current system, type:

$ ps aux

If you want to find out the ID of a particular running process, and you can use ps command and grep command, type:

$ ps aux | grep ProcessName
$ ps aux | grep systemd

Outputs:

[[email protected] ~]$ ps aux | grep systemd
root 1 0.2 1.0 179120 13924 ? Ss 01:09 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
root 601 0.0 0.6 93408 8936 ? Ss 01:09 0:00 /usr/lib/systemd/systemd-journald
root 634 0.0 0.8 117304 11104 ? Ss 01:09 0:00 /usr/lib/systemd/systemd-udevd
dbus 790 0.1 0.4 70824 6112 ? Ssl 01:09 0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
root 798 0.0 0.5 82880 7052 ? Ss 01:09 0:00 /usr/lib/systemd/systemd-machined
root 871 0.0 0.7 95232 9568 ? Ss 01:09 0:00 /usr/lib/systemd/systemd-logind
gdm 956 0.0 0.7 93136 9596 ? Ss 01:09 0:00 /usr/lib/systemd/systemd --user
gdm 1016 0.0 0.3 81876 5332 ? Ssl 01:09 0:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
devops 2190 0.0 0.7 93176 9596 ? Ss 01:12 0:00 /usr/lib/systemd/systemd --user
devops 2257 0.0 0.3 81424 4916 ? Ssl 01:12 0:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
devops 2356 0.0 0.0 12112 1088 pts/0 R+ 01:20 0:00 grep --color=auto systemd

Kill a Process using kill Command


If you want to kill a running process(such as: httpd) at the shell prompt on your system, and you can use kill command. before killing a process, and you need to find out the ID of process using above command or another command called pidof. type:

$ pidof httpd

or

$ ps aux | grep httpd

or

$ pgrep httpd

Outputs:

[[email protected] ~]$ pidof httpd
3140 3137 3136 3135 3126

[[email protected] ~]$ ps aux | grep httpd
root 3126 0.1 0.8 280224 11080 ? Ss 01:34 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3135 0.0 0.6 292440 8572 ? S 01:34 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3136 0.0 0.8 1350212 11884 ? Sl 01:34 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3137 0.0 1.0 1481348 13932 ? Sl 01:34 0:00 /usr/sbin/httpd -DFOREGROUND
apache 3140 0.0 0.8 1350212 11880 ? Sl 01:34 0:00 /usr/sbin/httpd -DFOREGROUND
devops 3356 0.0 0.0 12112 1072 pts/0 R+ 01:35 0:00 grep --color=auto httpd

[[email protected] ~]$ pgrep httpd
3126
3135
3136
3137
3140

once you get process ID, and you can use the kill command to kill that process, type:

$ sudo kill -9 PID

Kill a Process using killall or pkill Command


You can also use killall or pkill command to kill process by name from the command line:

$ sudo killall -9 httpd

or

$ pkill -9 httpd

Conclusion


You should know that how to force terminate a process using kill/pkill/killall commands in your CentOS or RHEL or Ubuntu Linux system.

You might also like:

Sidebar



back to top