How to pkill pid
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- pkill sends signals to processes based on criteria like PID, name, or user.
- The most common signal for termination is SIGKILL (signal number 9), which cannot be caught or ignored by the process.
- Using `pkill -9` is a forceful way to stop a process and should be used cautiously.
- To find a process's PID, you can use commands like `ps aux | grep <process_name>` or `pgrep <process_name>`.
- Always verify the PID before using `pkill -9` to avoid terminating critical system processes.
What is pkill?
The `pkill` command is a powerful utility in Unix-like operating systems (like Linux and macOS) that allows you to send signals to processes based on specified criteria. Unlike the `kill` command, which typically requires you to know the exact Process ID (PID) of the process you want to affect, `pkill` can identify processes by name, user, or other attributes. This makes it very convenient for terminating multiple processes at once or when you don't immediately have the PID.
Understanding Process IDs (PIDs)
Every running process on your system is assigned a unique number called a Process ID (PID). This PID is essential for the operating system to manage and track individual processes. Commands like `ps` and `top` display PIDs, and tools like `kill` and `pkill` use them to target specific processes.
How to pkill a Process by PID
While `pkill` is often used with process names, it can also be used directly with a PID. To do this, you combine the `pkill` command with the `-PID` option (though this is less common) or, more typically, you specify the PID directly after the command and any options. The most common and effective way to forcefully terminate a process using its PID with `pkill` is by sending the SIGKILL signal.
Using SIGKILL (Signal 9)
The SIGKILL signal (represented by the number 9) is a 'hard' kill. When a process receives SIGKILL, it is terminated immediately by the operating system without any opportunity to clean up, save its state, or perform graceful shutdown procedures. This is useful when a process is unresponsive and won't terminate with gentler signals (like SIGTERM, signal 15, which is the default for `kill` and `pkill` if no signal is specified).
The syntax to pkill a process using its PID and the SIGKILL signal is:
pkill -9 <PID>For example, if you have a process with PID 12345 that you want to stop immediately, you would run:
pkill -9 12345Finding the PID
Before you can pkill a process by its PID, you need to know what that PID is. Here are a couple of common ways to find it:
- Using `ps` and `grep`: This is a classic method. You list all running processes and then filter the output for the process name you're interested in. For instance, to find the PID of a Firefox process:
ps aux | grep firefoxThe output will show lines containing 'firefox'. The PID is usually the second column. Be aware that `grep firefox` itself might show up in the results; you'll want the PID of the actual Firefox process.
- Using `pgrep`: This command is specifically designed to find PIDs based on process names or other attributes. It's often more direct than `ps | grep`. To find the PID of Firefox:
This command will directly output the PID(s) of matching processes.pgrep firefox
When to Use `pkill -9 PID`
The `pkill -9 PID` command should be considered a last resort. It's best used when:
- A process is completely unresponsive and not terminating via normal means.
- You need to quickly stop a runaway process that is consuming excessive resources.
- You are absolutely certain about the PID and the consequences of terminating that specific process.
Cautionary Notes
Terminating the wrong process can lead to system instability or data loss. Always double-check the PID and the process name associated with it before executing a `pkill -9` command. If you are unsure, it's safer to use the `kill` command with the default SIGTERM signal first (`kill PID`), which allows the process to attempt a graceful shutdown, and only resort to `pkill -9 PID` if necessary.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- pkill(1) — Linux man pagepublic-domain
- kill(2) — Linux man pagepublic-domain
- Signals - Bash ManualGPLv3
Missing an answer?
Suggest a question and we'll generate an answer for it.