how to kill process in Linux

Windows Articles

How to install KVM on Debian 10?

Hello friends, in this post I will show you how to install KVM on Debian 10. KVM stands for...

How to open Windows 10 Mobility Center

Hello! There are many types of users of Windows 10. As it depends on the type of hardware used. That is, the...

Ubuntu 20.04.1 available

Canonical, the company led by Mark Shuttleworth, releases Ubuntu 20.04.1. It has a new image, with updates and security patches for the...

How to install Linux Kernel 5.8 on Ubuntu 20.04?

Upgrading the Linux Kernel can be a beneficial task, but it is always optional. Recently we talked about the Linux Kernel 5.8...

How to activate XPS Viewer in Windows 10

Hey, what's up! When working with Windows 10 we probably use a lot of files. Indeed, these files have many extensions. For...
Muhammad Nabeel
Muhammad Nabeel
Network and System Administrator

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.

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

OR

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.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install KVM on Debian 10?

Hello friends, in this post I will show you how to install KVM on Debian 10. KVM stands for...

How to open Windows 10 Mobility Center

Hello! There are many types of users of Windows 10. As it depends on the type of hardware used. That is, the...

Ubuntu 20.04.1 available

Canonical, the company led by Mark Shuttleworth, releases Ubuntu 20.04.1. It has a new image, with updates and security patches for the...

How to install Linux Kernel 5.8 on Ubuntu 20.04?

Upgrading the Linux Kernel can be a beneficial task, but it is always optional. Recently we talked about the Linux Kernel 5.8...

How to activate XPS Viewer in Windows 10

Hey, what's up! When working with Windows 10 we probably use a lot of files. Indeed, these files have many extensions. For...