Linux:How To Use Pkill/Kill Command To Kill Linux Processes

Normally If one process occupied too much cpu useage or memory usage, then you will consider that if that process should be killed. or For unknow process or virus process, we must kill those process. In this post , you’ll see how to use pkill command to kill linux processes or end user’s session. how to use kill command to kill linux processes.

​Use kill To Kill Linux Processes


The first thing is you need to find the process name or process id that you want to kill. then you can use ps command piped through grep command to find the process you want to kill, issue the following command:

ps -ef | grep httpd

See Output:

[root@devops ~]# ps -ef | grep http

root      7503     1  2 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7505  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7506  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7507  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7508  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7509  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7510  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7511  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7512  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

root      7514  7477  0 22:40 pts/0    00:00:00 grep http

Next, you can use kill command to kill the process, such as: kill 7505 process, type the following command:

kill -9 7505

Output:

[root@devops ~]# kill -9 7505

[root@devops ~]# ps -ef | grep http

root      7503     1  2 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7506  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd


apache    7507  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7508  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7509  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7510  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7511  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7512  7503  0 22:40 ?        00:00:00 /usr/sbin/httpd

root      7514  7477  0 22:40 pts/0    00:00:00 grep http

Use Pkill To Kill Process


You have been seen the above output , there are lots of httpd process, Do we have way to kill all of httpd process or how to end all apache user session.

So the below example will show you on using pkill command to kill all process owned by Apache user. issue the following command:

pkill -9 -u apache

Output:

[root@devops ~]# ps -ef | grep http

apache    7506     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7507     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7508     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7509     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7510     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7511     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

apache    7512     1  0 22:40 ?        00:00:00 /usr/sbin/httpd

root      7525  7477  0 22:47 pts/0    00:00:00 grep http

[root@devops ~]# pkill  -9 -u apache

[root@devops ~]# ps -ef | grep http

root      7528  7477  0 22:55 pts/0    00:00:00 grep http

[root@devops ~]#

pkill command also support regular expression, so you can give a pattern to match process name you want to kill. such as: pkill httpd. it will kill all process that match “httpd” pattern.

See Also:

You might also like:

Sidebar



back to top