How To Kill A Running Process In Linux/Unix?
 

How To Kill A Running Process In Linux/Unix?

 

This post was last updated on August 1st, 2020 at 12:44 pm

In Linux, a process is an instance of a program that is running on a computer. When a program starts executing it can have multiple processes associated with it. These processes can either run by a user or by the operating system itself.  Usually, a process terminates on its own when they are done with their task.

Sometimes a process hanged up and starts consuming a lot of system resources such as CPU or RAM. Linux provides kill command to terminate such a process from the system. Ahead in this article, we will discuss finding and killing a process in Linux or Unix.

Process Identifier (PID)

The process identifier or PID is a number that is used by an operating system to identify an active process uniquely. PID can be used for tasks such as changing the priority of execution or killing processes altogether.

List the running processes in a system –

You can use top utility to see a list of running processes in a system with some other information regarding resource utilization and the priority of a process. Use the following command in your terminal –

top

This will display like given in the image below. Here you can identify a process with its process id if you want to kill it.

Or you can find the process id of a process by its name. To find PID use the following command in your terminal –

pidof gnome-shell

Or to find the process id of firefox use –

pidof firefox

You can see the output of the pidof command in the given images.

Linux processes and signals

A signal is a notification, a message sent by either the operating system or some application to a program. In Linux when a process is killed a terminating signal is delivered to the process. Linux kernel implements about 30 signals, each of them is identified by a number, from 1to 31. Some commonly used signals are given below –

  1. SIGHUP(1) –  Hangup a process. Use it to reload configuration files or open and close log files.
  2. SIGKILL(9) – Kill signal. Use it to forcefully kill a process.
  3. SIGTERM(15) – Termination signal. It is the default and safest way to kill a process.
  4. SIGSTOP(17,19,23) – Stop process

How to kill a process in Linux?

There are various commands such as kill, pkill, killall, etc that you can use to kill a process in Linux. The kill command is very straightforward all you need to have PID to kill a process. Now run the following command –

kill PID

For example –

pidof vlc

Here process id of vlc is 5402. To kill this process use the following command in your terminal –

kill 5402

To kill vlc forcibly use –

kill -9 5402

How to use pkill command to terminate a process Linux?

The pkill command allows you to kill the processes based on partial matches. Suppose you want to kill the processes containing the name vlc in their name. Then use the following command in your terminal –

pkill vlc

To forcibly kill all the processes associated with vlc use-

pkill -9 vlc

How to use the killall command to kill the processes?

This is one of the easiest ways to kill a process from the terminal. Now if you know the exact name of the process then you can use the following command in your terminal –

killall vlc

Or to kill it forcibly use –

killall -9 vlc

Conclusion

In this article, you learned to kill unwanted processes. Now if you have any queries related to this topic then you can write to us in the comments below.

Previous How To Find UID And GID Using Id Command In Linux/Unix?
Next How To Display The System Information Using uname Command In Linux/Unix?
 

About author

You might also like

Linux Topics 0 Comments

How to Configure Sudo to run Without Password or Password-less

This post was last updated on August 2nd, 2020 at 11:21 amIf you are using the Linux operating system in your system which does not need much security or you

Linux Topics 0 Comments

How To Install a Package From .tar.gz Or .tar.bz2 File In Linux?

This post was last updated on October 25th, 2020 at 10:02 amA file archiver is used to hold multiple files into a single archive file. And a file compression utility is

Installation 0 Comments

How To Install Android Studio on Ubuntu?

This post was last updated on August 1st, 2020 at 02:56 pmAndroid studio is the official IDE for android application development by Google. It is based on JetBrains’ IntelliJ IDEA

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply