DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk10 min

How to Kill a Process in Linux: A Safe Guide to kill, pkill and killall

A practical Linux guide to choosing kill, pkill, and killall, with safe workflows, exact matching, process groups, permissions, PID-reuse warnings, and escalation advice.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use kill PID when you know the exact process ID, pkill pattern when you need attribute-based matching, and killall name when a command-name-wide action is intentional. All three send SIGTERM by default, giving a program an opportunity to shut down cleanly. Escalate to SIGKILL (-9) only after checking the target and confirming that it is truly stuck.

Choose the command by how precisely you can identify the process

Linux does not treat “the process” as a single universal target. A program may have several instances, worker processes, children, or processes with similar names. The safest command is the one whose selection rule matches what you actually know.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Goal Command pattern How it selects targets Main caution
Stop one known process kill PID Exact process ID Verify the PID first; the default is SIGTERM.
Stop selected matches pkill pattern Extended regular expression plus filters such as user, parent, group, terminal, age, exact name, or full command line The default name field is limited to 15 characters. Use -x or -f deliberately.
Stop every matching command name killall name Command name, with optional regular-expression, user, namespace, age, group, or interactive filters A broad name can terminate several processes. Narrow or confirm the selection.

What a Linux signal actually does

The commands do not directly “delete” a process. They ask the kernel to deliver a signal. The process may handle, ignore, block, or act on that signal, depending on its state and the signal type.

SIGTERM: the normal first request

SIGTERM is signal 15 and is the default for kill, pkill, and killall. A program can install a handler that closes files, flushes data, releases locks, closes sockets, and exits in an orderly way. This is why a graceful request should be your first step.

SIGKILL: an unconditional escalation

SIGKILL is signal 9. It cannot be caught or handled, so the target receives no opportunity to clean up. Use kill -KILL PID or kill -9 PID only after confirming the PID and allowing a reasonable interval for SIGTERM. Abrupt termination can leave temporary files, partially written data, stale locks, or unfinished transactions.

Signal 0: check without sending a termination signal

kill -0 PID sends no signal. It checks whether the process exists and whether your credentials permit signaling it. A successful return does not mean the process is healthy; it only means the existence and permission check passed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safe workflow: inspect, terminate gracefully, then escalate

  1. Inspect the process list. Use a process viewer or ps to identify the PID, complete command, and owner. For example, ps -eo pid,ppid,user,stat,etime,args displays the fields most useful for verification.
  2. Check identity and scope. Make sure the PID belongs to the application you intend to stop, not a similarly named service, a parent process, or a process belonging to another user.
  3. Send SIGTERM. Run kill PID or the explicit form kill -TERM PID.
  4. Observe the result. Refresh the process list or use kill -0 PID. Some programs exit immediately; others need time to finish work.
  5. Escalate only if necessary. If the same, verified process remains and cannot complete, use kill -KILL PID. Recheck the PID immediately before doing so.
  6. Verify the aftermath. Confirm that the process and any intended child processes are gone, and check the application’s logs for interrupted work or recovery actions.

A shell command assembled from an earlier process listing can be unsafe: a PID can disappear and later be assigned to an unrelated process. Avoid blindly piping stale PIDs into a destructive command. Recheck the target as close as possible to the signal operation.

Using kill when you know the PID

Basic forms

kill PID
kill -TERM PID
kill -15 PID
kill -KILL PID
kill -9 PID

The util-linux manual defines kill as sending the specified signal to specified processes or process groups. Signal names may be written with or without the SIG prefix, and signal numbers are accepted. kill -l lists the names recognized by your system.

Targeting a process group

Not every numeric argument means one process. PID 0 targets every process in the caller’s current process group. A negative value less than -1 targets the process group whose ID is the absolute value, so kill -TERM -- -1234 sends SIGTERM to process group 1234. The -- prevents the negative group ID from being parsed as an option.

Group-wide signaling can be useful for a job you started in a shell, but it can also terminate more processes than expected. Inspect the group membership before using it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Shell builtin versus external util-linux kill

Most shells provide a builtin named kill. Its options can differ slightly from the external util-linux command. To identify the external implementation and its version, run /bin/kill --version. Consult the shell’s help output, such as help kill in compatible shells, when a script depends on a particular option.

Race-resistant references and sequenced signals

Current util-linux documentation describes PID:inode process references for race-free signaling on kernels 6.9 and later. It also documents --timeout, which can send follow-up signals after delays while tying them to the same process identity. These features are useful in automation where a PID might otherwise be reused between commands; verify that your installed util-linux and kernel support them before relying on them.

Using pkill for filtered selection

pkill sends a signal, by default SIGTERM, to every process matching an extended regular expression and any supplied filters. It is the middle ground between an exact PID and a command-name-wide operation.

Preview before signaling

Use pgrep with the same selection options to list candidates first. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pgrep -a -x worker
pgrep -a -f 'python3 .*worker.py'

The -a option displays the full command line where supported. Once the output contains only intended targets, replace pgrep with pkill.

Exact names and full command lines

Without special options, pkill matches the process name field, not necessarily the complete command shown by ps. The default name is limited to 15 characters on Linux. A long executable name can therefore be truncated, and a short pattern can match several commands sharing the same prefix.

  • -x requires an exact match for the selected name field.
  • -f matches the full command line, including arguments. This is useful when two instances use the same executable but different configuration files; it is also dangerous if the pattern is too broad.

For example, preview a single executable name with pgrep -x service, or preview a specific argument with pgrep -f 'service --config /etc/service-a.conf'. Use the identical expression with pkill only after reviewing the preview.

Useful attribute filters

Combine the pattern with filters to reduce accidental matches:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • -u USER limits matches to a real or effective user.
  • -P PPID limits matches to children of a particular parent PID.
  • -g PGID limits matches to a process group.
  • -t TTY limits matches to a terminal.
  • Age and recency selectors can target older or newer processes where supported by your procps-ng version.

Attributes are combined as a selection rule. Test the exact combination with pgrep first, especially when using regular expressions or a user-wide filter.

Examples

# Preview, then stop one exact process name owned by alice
pgrep -a -x -u alice worker
pkill -TERM -x -u alice worker

# Match a complete command line, then escalate only if needed
pgrep -a -f 'worker --queue=images'
pkill -TERM -f 'worker --queue=images'
# After rechecking the same target:
pkill -KILL -f 'worker --queue=images'

Because pkill can match several processes, never assume that a visually singular pattern selects one PID.

Using killall for command-name-wide actions

The psmisc implementation of killall sends a signal to all processes running any specified command name. This is appropriate when stopping every instance is intentional, such as shutting down all workers in a dedicated test environment. It is risky on a shared system where the same command name may belong to unrelated sessions or users.

Limit the selection

  • -e requires an exact match for long process names instead of relying on a truncated name.
  • -r treats the name as a regular expression.
  • -u USER limits matches by user.
  • -g selects process groups rather than individual processes.
  • -n PID restricts matches to the PID namespace of the specified process.
  • -o TIME selects processes older than the specified age; -y TIME selects younger processes.
  • -i asks for confirmation before killing each match.

Option availability and exact syntax depend on the psmisc version installed on your distribution, so check killall --help or its manual before scripting an uncommon filter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Examples

# Preview the name first with a process viewer, then terminate all intended workers
killall -TERM worker

# Require confirmation for each matching instance
killall -i -TERM worker

# Restrict the action to one account
killall -u alice -TERM worker

# Use a regular expression only when the broader match is intentional
killall -r -TERM 'worker-[0-9]+'

A name such as java, python, or node can represent many unrelated applications. Prefer a more specific name or combine user, age, namespace, and interactive filters.

Why a command can terminate more processes than expected

Short or truncated name matching

pkill normally examines a 15-character process-name field, while the command line shown by a process viewer may be much longer. Two executables can therefore appear distinct in ps but share the same name prefix to pkill. Use -x for an exact name or -f when the distinguishing information is in the arguments.

Regular expressions and shared command names

Both pkill patterns and killall -r can match multiple instances. Characters such as ., *, brackets, and alternation have regular-expression meanings. Quote the pattern so the shell does not expand it, and preview it with pgrep first.

Process groups, sessions, and namespaces

A process group can contain a foreground program and its children. A group signal intentionally reaches all members. Namespace filters matter in containers: the same numeric PID can refer to different processes from different PID namespaces, so identify the namespace before acting on a containerized service.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PID reuse

PIDs are recycled. A script that lists a PID, waits, and then signals it can hit a new process. Recheck identity, use a direct supervisor interface when one exists, or use util-linux’s identity-aware mechanisms on supported systems.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Permissions and common errors

Linux permits a signal when the sender has the required identity relationship with the target or has CAP_KILL in the target process’s user namespace. In practical terms, a normal user can generally signal processes with the same real or effective user identity, while another user’s service usually requires appropriate privileges.

Operation not permitted (EPERM)

This indicates an authorization problem or a capability mismatch. Confirm the target owner, run the command under the account that owns the process when appropriate, and check whether a service manager or container boundary controls it. Do not treat sudo kill -9 as a substitute for verifying the target.

No such process (ESRCH)

The process may have exited between inspection and signaling, or the PID may not be visible in your namespace. Refresh the process list and verify that you are operating in the expected host or container.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Permission checks with signal 0

kill -0 PID can distinguish “the process is absent” from “the process exists but I cannot signal it,” although a script should still handle races between the check and a later terminating signal.

When termination appears not to work

  • The program is handling SIGTERM. It may be flushing data or waiting for workers. Check logs and allow time for normal shutdown.
  • The process is in uninterruptible sleep. A task blocked in kernel I/O may not react immediately, even to SIGKILL. Investigate the underlying storage, network, or driver problem.
  • The process is a zombie. A zombie has already exited and is waiting for its parent to collect its status; killing the zombie itself does not remove it. The parent must reap it.
  • The command selected the wrong target. Re-run ps or pgrep and inspect PID, owner, namespace, and full command line.
  • A supervisor restarts it. System service managers, container orchestrators, and watchdogs may immediately launch a replacement. Stop or reconfigure the supervisor when that is the actual goal.

Waiting with killall -w

The psmisc killall -w option waits for signaled processes to disappear, checking approximately once per second. It can wait forever when a process ignores the signal, the signal has no effect, or the remaining entry is a zombie. The manual also warns about a race: a PID can vanish and be replaced between scans, so waiting is not an absolute proof that the original process identity remained unchanged.

For scripts, use an explicit timeout around your own polling logic, record the identity you intend to monitor, and define what should happen when the timeout expires. Never make an unbounded wait part of a critical shutdown path.

A practical decision guide

Use kill when

  • You have verified one PID.
  • You want the clearest, least ambiguous target.
  • You need process-group semantics and understand the group membership.

Use pkill when

  • The PID changes or is unknown, but you can describe the target with a name and attributes.
  • You need filters such as owner, parent, terminal, group, or full command line.
  • You will preview the same expression with pgrep first.

Use killall when

  • Stopping every instance of a command name is explicitly intended.
  • You can narrow the scope with exact, user, namespace, group, age, or interactive options.
  • You have checked that your system provides the psmisc implementation and its documented options.

Recommended command checklist

  • Identify PID, owner, full command line, process group, and namespace.
  • Preview pattern-based matches with pgrep.
  • Start with SIGTERM (15), not SIGKILL (9).
  • Use -x for an exact process name or -f for a deliberately chosen full command-line expression.
  • Assume killall name can affect multiple users or instances until filters prove otherwise.
  • Recheck the process immediately before escalation because PIDs can be reused.
  • Investigate permissions, namespaces, supervisors, zombies, and uninterruptible I/O when a signal appears ineffective.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.