0% found this document useful (0 votes)
8 views

How to Kill a Process in Linux from Command Line

This guide provides detailed instructions on how to kill unresponsive or resource-intensive processes in Linux using the command line. It covers various methods to find process IDs, including commands like ps, pgrep, and top, as well as different commands for terminating processes such as kill, killall, and pkill. The document emphasizes the importance of understanding these commands for effective system management and administration.

Uploaded by

Zac Ing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

How to Kill a Process in Linux from Command Line

This guide provides detailed instructions on how to kill unresponsive or resource-intensive processes in Linux using the command line. It covers various methods to find process IDs, including commands like ps, pgrep, and top, as well as different commands for terminating processes such as kill, killall, and pkill. The document emphasizes the importance of understanding these commands for effective system management and administration.

Uploaded by

Zac Ing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

https://phoenixnap.

com/kb/how-to-kill-a-process-in-linux

Home » KB » SysAdmin » How to Kill a Process in Linux from Command Line?


How to Kill a Process in Linux from Command Line?
By Vladimir Kaplarevic Published: April 28, 2025
Topics: Commands, Linux

If a Linux process becomes unresponsive or consumes excessive resources, killing it may be the only solution. Most
processes have their own methods of shutting down. Unfortunately, processes can malfunction and require running a
command to manually kill them.
This guide demonstrates how to kill a Linux process using the command line.

Prerequisites
• A system running Linux.
• A user account with root privileges.
• Access to the terminal.

How to Find Process ID or Process Name


Before killing a process, you need to locate it. Processes can be found by the process name (or a partial process
name) or the process ID (PID).
There are multiple ways to find a process in Linux:
• Via the ps command.
• Via the pgrep or pidof command.
• Via the top command.
The sections below show different ways to search for a process in Linux.
Locate a Process with ps Command
The ps command provides a complete listing of running processes, formatted based on the specified command
options. The syntax for the ps command is:

ps [options] Copy

The most common options to add to ps are:


• -a. View processes of all users rather than just the current user.
• -u. Provide detailed information about each of the processes.
• -x. Include processes that are controlled not by users but by daemons.
For example, the command ps -aux returns a detailed list of all processes:

Find PID with pgrep or pidof


The pgrep Linux command is a more complex way of finding a process. The pgrep command returns processes based
on specific selection criteria, known as the pattern. The pattern is a regular expression, such as a*, where * is a
wildcard.

pgrep [options] [pattern] Copy

The options that can be used with pgrep are:


• -l. List the process names and the PIDs.
• -n. Return the newest process.
• -o. Return the oldest process.
• -u. Only find processes that belong to a specific user.
• -x. Only find processes that exactly match the given pattern.
For example, the command pgrep -l -u root displays the names and PIDs of all processes owned by root:

The pidof command is used to find the ID of a process using the process name.

pidof [options] [program] Copy

Some of the options that pidof accepts are:


• -c. Only return PIDs within a single root directory.
• -o. Omit certain PIDs (include the processes to omit after the flag).
• -s. Only return a single PID.
• -x. Also returns PIDs of shells that are running scripts.
For example, to get the PID of the snapd process, run pidof snapd:

View Running Processes with top


The top command is the easiest way to get a complete overview of the currently running processes. To view a list of all
active processes, run the command:

top Copy

The top command interactive mode starts, shows the process IDs, the users, the amount of memory and CPU power
each process uses, the running time, etc.

To exit the top interface, press q.

How to Kill a Process


Make sure to consider permissions before killing or terminating a process. A root user can kill all processes. Either
add sudo before a command to run it as root, or obtain a root shell with the su command. Then, execute the
termination command.
Killing a process sends a termination message to the given process. There are multiple types of termination messages,
including:
• SIGKILL - The ultimate way of killing a process. It always kills a process abruptly, generating a fatal error. SIGKILL
should always work. If it doesn't, the operating system has failed.
• SIGTERM - It attempts to kill a process, but, unlike SIGKILL, it may be blocked or otherwise handled. It is a gentler
way of terminating a process.
For most purposes, SIGKILL is the fastest and most effective method to terminate the process.
The sections below list the most commonly used commands for killing a process and provide the steps for using each
command.
killall Command
The killall command kills processes by their name. By default, it sends a SIGTERM signal. The killall command can
kill multiple processes with a single command. The syntax is:

killall [process] Copy

The killall command accepts several options:


• -e. Find an exact match for the process name.
• -I. Ignore the case when trying to find the process name.
• -i. Ask for additional confirmation when killing the process.
• -u. Only kill processes owned by a specific user.
• -v. Report back on whether the process has been successfully killed.
The following example shows the use of the -i option, instructing killall to ask for confirmation before terminating the
process:

In addition to killing processes based on name, the killall command can also be used to kill based on the age of the
process. Use the following commands:
• -o. Use this flag with a duration to kill all processes that have been running for more than that amount of time.
• -y. Use this flag with a duration to kill all processes that have been running for less than that amount of time.
The killall -o 15m command kills all processes that are older than 15 minutes, while the killall -y 15m command kills
all processes that have been active for less than 15 minutes.
pkill Command
The pkill command is similar to the pgrep command, in that it kills a process based on the process name, in addition
to other qualifying factors. By default, pkill sends the SIGTERM signal. The syntax is:

pkill [options] [pattern] Copy

pkill options include:


• -n. Only kill the newest of the processes that are discovered.
• -o. Only kill the oldest of the processes that are discovered.
• -u. Only kill the processes owned by the specified user.
• -x. Only kill the processes that match the pattern exactly.
• -signal. Send a specific signal to the process, rather than SIGTERM.
The following example demonstrates how to kill the newest process created by the user bosko:

pkill -n -u bosko Copy

kill Command
The kill command terminates processes via the process ID. The syntax is:

kill [process ID] Copy

The kill command kills a single process at a time with the given process ID. It sends a SIGTERM signal instructing a
process to stop. It waits for the program to run its shutdown routine.
The -signal option can be used to specify a signal other than SIGTERM.
kill -9 Linux Command
https://phoenixnap.com/kb/how-to-kill-a-process-in-linux
kill -9 is used to shut down an unresponsive service. Run it similarly to the regular kill command:

kill -9 [processID] Copy

Or:

kill -SIGKILL [processID] Copy

The kill -9 command sends a SIGKILL signal to a service, shutting it down immediately. An unresponsive program
ignores a kill command, but it shuts down whenever a kill -9 command is issued. Use this command with caution since
it bypasses the standard shutdown routine, and any unsaved data will be lost.
xkill command
The xkill command is a special command that closes a given server's connection to clients. The syntax of the xkill
command is:

xkill [resource] Copy

If a server has opened some unwanted processes, xkill aborts these processes.
If xkill is run without specifying a resource, then an interface opens up to let the user select a window to close. For
example:

top Command
The top command provides an interface through which a user can navigate the currently running processes. To start
the interface, run the command:

top Copy

To kill a specific process, press k when in the interface, and enter the PID of the process to terminate:

 Note: Learn how to use the nohup command to block the SIGHUP signal and allow processes to
complete even after logging out from the terminal/shell.

Conclusion
This guide explained several ways to kill processes in Linux. It is critical to learn and understand these Linux
termination commands for system management and administration.
Next, check out our comprehensive article on Linux network commands, or take a sneak peek at our ultimate list of
Linux commands.

You might also like