20.7 C
Muhammad Nabeel
Network and System Administrator

how to kill process in Linux

A process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity. Several processes may be associated with the same program; for example, opening up several instances of the same program often results in more than one process being executed.

kill is a command which is used in several popular operating systems to send signals to running processes. In Linux kill command is normally used to terminate running process. In this article we will cover basics of kill command so you will understand it and apply it in your environment.

Before killing or terminating any process we have to get its process ID (PID) or process name. We can use wo commands to find process ID’s, first is “ps” command and the second it “top” command. In this article we will use ps command to find a process ID and its name.

Locate process using ps command

ps command is used to see processes, following command to list all running processes.

- Advertisement -
ps aux

a: Show processes for all users
u: Display the user who is using the process
x: Show all processes. (it also show the processes running in a GUI environment)

kill process in Linux

List specific process ID

If you want to search any specific process so you can use any of following three methods.

Method 1:

ps -aux | grep process-name

e.g check for Apache process

ps -aux | grep httpd

kill process in Linux

You can see process id’s of Apache in above image.

Method 2: Use pidof command

pidof httpd

Sample outputs:

4372 4371 4370 4369 4368 4361

kill process in Linux

Method 3: Use pgrep command

pgrep httpd

kill process in Linux

All above methods will show process ID’s of httpd (Apache) process.

Kill Process

kill command is use to terminate or kill running processes.

Method 1: Kill process by its process ID

Now, I will kill one Apache process using its process ID.

kill -9 4372

Then, verify that PID is killed

pidof httpd

kill process in Linux

So you can see in above image that process 4372 is no more exist.

Method 2: Kill process by its name

If you want to kill all the processes of a service you can use this method.

kill -9 httpd


pkill httpd

Now, verify process is killed.

pidof httpd

Then, you will see that all processes of httpd will no more exist.

Kill all processes of a User

You can use below command to show processes of a user.

ps -fu user-name

Now you will get process ID’s of that user. E.g I show process ID’s of user “osradar” in below image

kill process in Linux

Then, run below command to kill all processes of the user

kill -HUP process-ids

kill user in Linux

So, when you run again below command you will see no result.

ps -fu user-name

That’s it, You now know that how to kill running processes in Linux.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article