HiBlog
  • Home
  • Blog
  • Category
    • Most Interesting
      Most Interesting Posts
    • HiCademy
      Hosting and Server Articles
    • HiTube
      Educational Videos
    • HiCast
      Interesting Podcasts
  • About us
  • Contact Us
FA
EN
RU
Language:
FA
EN
RU
Article Stats
N/A
Category
Ali Ghanimati
Author
13 October 2025
Release Date
141
Views
FA
EN
RU
Post Languages
How to Stop a Process or Kill Process in Linux

How to Stop a Process or Kill Process in Linux

Table of Content

Article Stats
  1. How to Find Process ID or Process Name
  2. How to Kill a Process

When a process in the Linux operating system does not return a response or consumes a lot of hardware resources from our system, stopping or “killing” it may be the only option. Many processes have their own specific ways to stop. Unfortunately, processes may become faulty, or it may be necessary to enter a command manually to stop them.

In this tutorial, we will learn how to stop a process or Kill Process in Linux.

How to Find Process ID or Process Name

Before stopping a process, you need to find its location. This can be done by finding the running process name (Process Name) or its corresponding ID (Process ID or PID).

There are several ways to find a process in Linux:

  • Using the ps command
  • Using the pgrep or pidof commands
  • Or using the top commands in Linux

Finding a process using the ps command

The `ps` command displays a complete list of running processes based on the option we enter with it.

ps [option]

Each option has a specific feature and performs a specific task when entered. The options we can enter with the `ps` command are as follows:

  • Option -a. Displays all processes related to all users of the system.
  • Option -u. Provides detailed information about each process in the system.
  • Option -x. Displays processes controlled by daemons (programs that have been running since the system booted and are not controlled by users) and not by system users.

For example, the command ps -aux sends a complete list of all processes with their details:

Finding the Process ID or PID using the pgrep or pidof commands

In Linux, the pgrep command offers a more sophisticated way to find a process. The pgrep command returns processes based on a specific selection criterion called a pattern. The pattern is essentially a regular expression. For example, in the pattern a*, the * symbol means anything in place of any number of characters.


pgrep [options] [pattern]

The options for the pgrep command are as follows:

  • -l option. Provides a list of process names and their PIDs.
  • -n option. Displays the newest process.
  • -o option. Displays the oldest process.
  • -u option. Displays the processes related to a specific user on the system.
  • -x option. Displays processes that are exactly the same as the given pattern.

For example, the command pgrep -l -u root displays the process names and PIDs related to the root user on the system:

The pidof command is used to find the Process ID or PID by providing the process name.


pidof [options] [program]

Some of the options related to the pidof command are as follows:

  • Option -o. Stop using PID.
  • Option -s. Display only one PID.
  • Option -x. Display the PIDs of scripts that are being executed by system interpreters.

For example, to get the PID for the sshd process, we execute the command pidof sshd:

Finding running processes using the top command

The top command is the easiest way to get complete information about running processes. To see a complete list of running processes, use this command:


top

By running this command, an interactive mode is created from the top command, which displays various information such as PIDs, the users associated with each process, the amount of hardware resources (CPU and memory) consumed by each process, and also its execution time.

To exit the top command environment, use the q key.

How to Kill a Process

In fact, killing a process means terminating it in the system. To do this, first obtain the necessary permissions and make sure that your user access is capable of doing so.
A root user can kill all processes. Use the sudo command before executing any command to terminate a process to execute that command as the root user, or enter the shell environment as the root user before executing the commands.

Terminating or killing a process sends a message to the process to instruct it to end. These messages are called termination signals. There are several different types of termination signals:

  • SIGKILL signal. An excellent way to instruct a process to terminate. In this case, a process terminates abruptly with an error message. SIGKILL is a method that should always work. If SIGKILL doesn’t work, it means the operating system has an error or problem.
  • SIGTERM signal. Unlike SIGKILL, this signal may be blocked or otherwise handled. This signal is used to terminate a process in the system and is a relatively gentler way to do so.

For most uses, SIGKILL is a more practical and faster method for terminating a process.

killall command

The killall command terminates a process by receiving its name, or in other words, “kills” it. By default, this command sends a SIGTERM signal to do this. Also, killall has the ability to terminate multiple processes simultaneously with a single command entry.


killall [process]

The killall command includes several different options:

  • -e option. In addition to the named process, it also stops processes with the same name.
  • Option -I. Considers the process names without checking for case sensitivity, and terminates them.
  • Option -i. Before terminating a process, it asks the user to confirm the decision to terminate it. After user confirmation, the command is executed.
  • Option -u. Only terminates processes related to a specific user.
  • Option -v. After completing the process termination, it returns a message indicating the success of the operation.

In addition to the ability to terminate processes using the process name, the killall command also has the ability to terminate processes based on their age.

  • Option -o. Terminates all processes whose start time is older than the specified time.
  • Option -y. Terminates all processes whose start time is newer than the specified time.

For example, the command killall -o 15m terminates all processes that are older than 15 minutes, and the command killall -y 15m terminates all processes that are younger than 15 minutes.

pkill Command

The pkill command, similar to the pgrep command, terminates a process using its name. By default, the pkill command sends a SIGTERM signal:
pkill [options] [pattern]

The options for the pkill command are as follows:

  • The -n option. Terminates only the newest process.
  • The -o option. Terminates only the oldest process.
  • The -u option. Terminates only the process belonging to that user.
  • The -x option. Terminates only the process that has an exact matching pattern.
  • The -signal option. Sends a specific signal to the process instead of the default SIGTERM signal.

For example, this command terminates the newest process created by the root user:


pkill -n -u root

xkill Command

The xkill command is a specific command for disconnecting a server from its clients.

xkill [resource]

If unwanted processes are created on the server, we can stop them using xkill.
Also, if we execute the xkill command without any input, a new interface will open for the user to terminate the desired processes.

top Command

As we explained, the top command opens an interface with information about the running processes for the user.

top

This command also has the ability to terminate a process. After executing the top command, by pressing the k key and entering the PID of a process, we can terminate it.

Share Post
hidata.org/en/blog/how-to-kill-a-process-in-linux/
Copy Link
In Social Media

Add Comment

You’re replying to
captcha
Web Hosting
  • Professional cPanel Hosting
  • High-Traffic cPanel Hosting
  • File Hosting
Dedicated Server
  • Europe Dedicated Server
About HiData
Hi Data
Good Hosting Experience
Since April 2014, HiData has been hosting thousands of online businesses with strong and premium infrastructure in the best datacenters in Iran and worldwide. We use new-generation servers with powerful processors, high-capacity networks, and strict data security policies to meet your hosting needs at the highest standards. Our support team is available 24/7 through ticket and phone. Speed, stability, and peace of mind are not just promises. They are the identity of HiData.
Virtual Server
  • Germany NVMe VPS
  • Russia NVMe VPS
  • Turkey SSD VPS
  • Germany SATA VPS
  • Storage VPS
  • Cloud VPS
Other Services
  • Domain Services
  • Licensing System
  • Reseller
Phone 1: +98-9009019
HiTube HiCademy HiCast HiBlog
Address
HQ Address: Unit 8, 2nd Floor, Tala Commercial Complex, Imam Khomeini St., Abhar
Contact Phones
+98-9009019
24/7 Support
Support Email: info@hidata.org
© 2025 HiData
All rights reserved for hidata.org
HiData Store
The best prices for the world's leading brands