[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedJuly 3, 2023

How to kill a process.

How To Kill A Process.

In this article, we will show you how to use kill, killall, and pkill commands to terminate a process.

The main difference between these tools is that kill terminates processes based on Process ID number (PID), while the killall and pkill commands terminate running processes based on their names and other attributes.

 

System Kill Signals.

kill, killall, and pkill send a given signal to specified processes or process groups. When no signal is specified, each tool sends 15 (TERM).

The most commonly used signals are:

  • 1 (-HUP): to reload a process.

  • 9 (-KILL): to kill a process.

  • 15 (-TERM): to gracefully stop a process.

Signals can be specified in three different ways:

  • using a number (e.g., -1)

  • with the “SIG” prefix (e.g., -SIGHUP)

  • without the “SIG” prefix (e.g., -HUP).

Use the -l option to list all available signals:

kill -l  # or killall -l

 

Terminating Processes Using the kill Command

To terminate a process with the kill command first, you need to find the process PID. You can do this using different commands such as top, ps , pidof, and pgrep .

Let’s say the chrome browser has become unresponsive, and you need to kill the browser process. To find the process ID, use the pidof command:

pidof chrome

The command will print all chrome processes:

2551 2514 1963 1856 1771

Once you know the chrome processes PIDs to terminate all of them send the TERM signal:

kill -9 2551 2514 1963 1856 1771

 

Terminating Processes Using the killall Command

The killall command terminates all programs that match a specified name.

Using the same scenario as before, you can kill the chrome process by typing:

killall -9 chrome

killall accepts several options such as sending signals to processes owned by a given user, matching processes names against regular expressions, and the creation time. You can get a list of all options by typing killall (without any arguments) on your terminal.

For example, to terminate all processes running as a user “sara”, you would run the following command:

sudo killall -u sara

 

Terminating Processes Using the pkill Command

pkill terminates processes that match the pattern given on the command line:

pkill -9 chrome

The name of the process doesn’t have to be an exact match.

With pkill you can also send a signal to processes that are owned by a given user. To kill only the chrome processes owned by the user “sara”, you would type:

pkill -9 -u sara chrome

 

Conclusion

Terminating unresponsive programs using the kill, killall and pkill commands is an easy task. You only need to know the process name or PID.

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM