Thursday, July 18, 2024
HomeCentosUse of Kill Command in Linux

Use of Kill Command in Linux

Most processes have their own strategies for closing down. Shockingly, processes can breakdown and not permit themselves to be closed down. So,if a running background measure is unresponsive, it gets important to use a command to kill it. 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 that is used in many operating systems to send signals to the running processes. But in linux kill command is normally used to terminate running process. The kill command can be executed in many ways. So, in this very article we gonna cover basics of kill command so, you gonna understand and then applies in your environment.

Before kill or terminate any process we must know its process ID (PID) or process name, so to find a process name we have two commands which can be run. First is “ps” command and the second it “top” command. So, in this artice we will use ps command to find a process ID and its name.

Find process using ps command

ps command used to check processes, the below command is used 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 shows the processes running in a GUI environment)

List specific process ID

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

Procedure 1:

ps -aux | grep process-name

We gonna check for vsftpd(FTP server) process

ps -aux | grep vsftpd

As you can see process ID of vsftpd in following image.

Procedure 2: Use pidof command

pidof vsftpd

Sample outputs:


Procedure 3: Use pgrep command

pgrep vsftpd

All above Procedure gonna show you process ID’s of vsftpd process.

Kill Process

kill command used to terminate or kill running processes.

Procedure 1: Kill process by its process ID

Now I will kill one vsftpd process using its process ID.

kill -9 17702

now verify that PID is killed

pidof vsftpd

You can see in below image that process 17702 is no more exist.

Procedure 2: Kill process by its name

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

kill -9 vsftpd


pkill vsftpd

Now verify that process is killed

pidof vsftpd

Now you will see that all processes of vsftpd will no more exist.

Kill all processes of a User

To show all running processes of a user, run below command

ps -fu user-name

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

Now run below command to kill all processes of that user.
You need to make sure that you are going to use following command while your are login on a root user. On other hand if you run following command while working from a user then your session will be terminated.

kill -HUP process-ids
kill -HUP 46397 46406 46416 46417 46421 46476

Now when you run following command again there you gonna see no result of it.

ps -fu user-name

That’s about it.
Now you get enough idea that how to kill running processes in linux.



Please enter your comment!
Please enter your name here

Most Popular