How to Terminate a Process in Linux

When managing a Linux system, you may encounter a situation where a process becomes unresponsive or needs to be manually stopped. Knowing how to terminate a process in Linux is a key skill for both system administrators and developers.

 What Is a Process in Linux?

A process is an instance of a running program. Every process in Linux has a unique PID (Process ID), which is used to monitor or control it.

You may want to terminate a process if:

  • It’s consuming too many resources

  • It’s stuck or frozen

  • You need to restart the service or application

  • You want to manually stop a background script or daemon

Step 1: Identify the Process

Before you terminate anything, you need to find out the PID of the process. Here are a few ways:

✅ Using ps

ps aux | grep process_name

✅ Using top or htop

  • Run top and find the PID in the leftmost column.

  • htop (if installed) offers an interactive, user-friendly interface.

✅ Using pidof

pidof process_name

This returns the PID(s) directly, if the process name is known.

 Step 2: Terminate the Process

🔹 Method 1: kill (By PID)

Send a termination signal (default is SIGTERM – signal 15):

kill <PID>

🔹 Method 2: kill -9 (Force Termination)

If the process won’t stop with a normal kill signal, use SIGKILL (signal 9):

kill -9 <PID>

This forces the process to stop immediately.

🔹 Method 3: killall (By Name)

To terminate all processes with a specific name:

killall process_name

You can also add -9 to force it:

killall -9 firefox

🔹 Method 4: pkill (Pattern Matching)

pkill allows matching process names with regex-style patterns:

pkill process_name

Or forcefully:

pkill -9 process_name

🔹 Method 5: xkill (For GUI Applications)

If you’re running a Linux desktop and need to kill a graphical application:

  1. Run:

    xkill
  2. Click on the window you want to terminate.

Note: xkill must be installed and X server must be running.

 Common Signals

SignalNumberDescription
SIGTERM15Graceful stop
SIGKILL9Forceful, immediate kill
SIGHUP1Hang up / restart daemon
SIGINT2Interrupt (like Ctrl+C)

Things to Keep in Mind

  • Always try graceful termination (kill) before using forceful methods like kill  -9.

  • Make sure you double-check the PID so you don’t kill an important system process.

  • For critical services, it’s better to use system management tools like systemctl:

    sudo systemctl restart apache2

If you frequently manage processes, install htop:

sudo apt install htop # Debian/Ubuntu
sudo yum install htop # CentOS/RHEL

This tool lets you interactively kill processes by selecting them and pressing F9.

By mastering these tools, you gain more control over your Linux environment and ensure that stuck or rogue processes don’t compromise system performance.