October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

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

A practical Linux guide to stopping one process or many: compare kill, pkill and killall, preview matches, use SIGTERM first, and escalate safely when necessary.
WorldLinux: A Safe Guide to kill, pkill and killall Length12 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use kill PID to signal one known process, pkill to select processes by a pattern and attributes, and killall to target processes by command name. Each defaults to SIGTERM, which gives a program an opportunity to save data and release resources. Verify the target first, wait briefly, and use SIGKILL (kill -9) only when a confirmed process will not exit normally.

kill, pkill or killall: which command should you use?

Goal Command pattern How targets are selected Main caution
Stop one known process kill PID One exact process ID Confirm the PID; the default signal is SIGTERM.
Stop selected matches pkill pattern An extended regular expression plus filters such as user, parent, group, terminal, age, exact name or full command line The default process-name field is limited to 15 characters. Use -x or -f deliberately.
Stop every process with a command name killall name Command name, with optional regular-expression, user, namespace, age, group and interactive filters A short or broad name can match several processes.

The commands are selectors, not different kinds of signals. By default, all three send SIGTERM (signal 15). Their important difference is how they decide which processes receive it.

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.

What a Linux signal does

A signal is a small asynchronous notification delivered to a process or process group. The receiving program may handle, block or ignore many signals. SIGTERM is the conventional orderly-shutdown request: a program can close files, flush saves, remove temporary data, close sockets and then exit.

SIGKILL is signal 9. The kernel terminates the target immediately, and the target cannot catch, block or handle it. That removes any opportunity for cleanup, so a forced kill can leave a lock file, partial save, interrupted database transaction or open-session state behind. A normal escalation is therefore:

  1. Send SIGTERM and allow the application time to shut down.
  2. Check whether the same process is still present.
  3. Send SIGKILL only after reconfirming the identity and accepting the cleanup risk.

You can name a signal (TERM, KILL), prefix it with SIG, or use its number. For example, kill -TERM 4821, kill -SIGTERM 4821 and kill -15 4821 request the same signal. kill -l lists names supported by the current environment.

Inspect the process before sending anything

A PID can be reused after a process exits. Never copy a PID from an old terminal line and assume it still identifies the same program. Inspect the current process table immediately before signaling:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ps -eo pid,user,ppid,pgid,stat,comm,args --sort=pid

For a narrower view, search by the account that owns the process:

pgrep -a -u "$USER" game

The -a option prints the PID and command line. Treat the output as a preview, not as permission to kill every line that looks similar. Confirm the PID, executable or command line, owner, parent and, when relevant, process group. A game launcher, compatibility layer and game executable can be separate processes; terminating the launcher may not stop the child, while a pattern aimed at the child could match several sessions.

If you only need to test whether a PID exists and you are allowed to signal it, signal number zero performs a permission and existence check without delivering a terminating signal:

kill -0 4821

A successful command does not mean the process is healthy; it means the kernel accepted the existence and permission check. An error such as “No such process” means the PID is gone, while “Operation not permitted” points to an identity, capability or namespace boundary.

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

Stop one known process with kill

Graceful termination

Once you have verified the current PID, send the default request:

kill 4821

Being explicit can make scripts easier to audit:

kill -TERM 4821

The kill utility sends the selected signal to specified processes or process groups. It does not mean “force close” by itself. A well-behaved application handles SIGTERM and exits in an orderly fashion.

Wait and verify

There is no universal delay that suits every program. A graphical game may need time to write a save, while a small command-line helper should disappear almost immediately. Recheck the process rather than blindly issuing another command:

ps -p 4821 -o pid=,user=,stat=,comm=,args=

If the command prints nothing, that PID no longer exists. If it remains, inspect its state and decide whether more time, a different signal or a service-level fix is appropriate.

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

Force termination only as a last resort

After reconfirming that PID 4821 is still the intended target, use:

kill -KILL 4821

or:

kill -9 4821

SIGKILL cannot be caught and gives the process no cleanup opportunity. It also cannot make an uninterruptible kernel wait complete immediately; a task stuck in an uninterruptible state may remain visible until the underlying I/O returns. If the process is a child of a supervisor, it may also be started again after either signal.

Use pkill when selection needs a pattern or filters

pkill sends the selected signal to every process matching its criteria. Its pattern is an extended regular expression applied to the process name by default. For example:

pkill -TERM -x game-client

-x requires the process name to match exactly. Without it, a pattern can match names containing the expression. The default name is the kernel’s process-name field, which is limited to 15 characters. Long executable names may therefore be indistinguishable when only the default name is examined.

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

Match the complete command line with -f

Use -f when the distinguishing text appears in arguments or when the executable name is truncated:

pkill -TERM -f 'server --port 27015'

Full command-line matching is powerful and correspondingly easier to overmatch. Quote the expression so the shell does not reinterpret it, and preview it first where practical:

pgrep -a -f 'server --port 27015'

Then run the equivalent pkill only if every listed process is intended.

Constrain pkill by identity and relationships

Pattern matching can be combined with attributes. Common examples include selecting a user with -u, a parent process with -P, a process group with -g, a terminal with -t, or an exact name with -x. These filters are useful when several users run similarly named game servers or when a launcher and its children share part of a command line.

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.
pkill -TERM -u player -x game-server

Read the local pkill manual for the exact option spelling supported by your procps-ng version. A successful pkill can affect more than one PID; its contract is to signal each matching process rather than print a list.

Use killall for intentional command-name-wide action

killall selects processes by command name. This is appropriate when every instance of a named service or helper should stop:

killall -TERM game-server

It is not a synonym for “kill one process.” If three users run game-server, all three can receive the signal unless you narrow the selection.

Useful killall narrowing and confirmation options

  • -u user limits matches to a user.
  • -g group selects processes in a process group.
  • -n seconds selects processes newer than the specified age.
  • -o seconds selects processes older than the specified age.
  • -y seconds selects processes younger than the specified age.
  • -e requests exact matching, including handling for names longer than the usual displayed command-name field.
  • -i asks for interactive confirmation before terminating each match.

For example, an account-scoped, interactive stop is less surprising than a machine-wide name match:

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.
killall -TERM -u player -i game-server

Check the installed manual because option combinations and namespace behavior depend on the psmisc version. A broad name should never be placed in an unattended script without an additional identity or age constraint.

Why killall -w can hang

The -w option waits for processes to disappear and checks roughly once per second. The wait can last forever if a process ignores the signal, the signal has no effective result, or the process remains a zombie. It also has a race: a PID can disappear and be replaced between scans, so waiting is not a perfect identity guarantee. Use it only when an indefinite wait is acceptable and the process lifecycle is understood.

Choosing between pkill and killall

Use pkill when the distinction is a pattern plus process metadata: a particular account, parent, process group, terminal, age or full command line. Use killall when the operational intent is expressed as a command name, especially when all instances of that name should receive the signal. Neither command is inherently safer; safety comes from making the match narrower than the set of processes you are willing to stop.

For a long executable name, first determine whether the visible name is truncated. A default pkill match can see only the first 15 characters, so two programs with the same prefix may be indistinguishable. Switching to -f and including a distinctive argument can separate them. Conversely, full command-line matching sees arguments from every matching process, so a short expression such as server can select far more than the intended instance. An exact -x name match or an account filter is preferable when it expresses the requirement clearly.

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

killall also supports regular-expression and namespace-related selection on implementations that provide those options. The -e and -i choices are useful safeguards when a command name is long or when a human should approve each match. Always check the installed manual: killall is provided by psmisc, while pkill is part of procps-ng, and option details can vary by version.

Process groups, special PIDs and signal zero

kill can target more than one process through process-group semantics:

  • PID 0 refers to the caller’s current process group.
  • A negative value below -1 refers to the process group whose ID is the absolute value. For example, kill -- -7310 signals process group 7310; the -- prevents the negative number being parsed as an option.
  • A positive PID addresses one process.
  • Signal 0 delivers no signal but checks whether the target exists and whether signaling would be permitted.

Group operations are useful for a foreground job or a deliberately isolated server, but they can terminate every member of that group. Inspect the PGID column before using a negative target.

Be especially careful when combining a group target with SIGKILL. A process group can contain a shell, launcher and worker processes, so one command may remove all of them without giving any member a chance to clean up. If only one worker is intended, address its positive PID instead.

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

Permission errors, namespaces and vanished PIDs

Linux permits a signal when the sender has the required identity relationship with the target or has the CAP_KILL capability in the target process’s user namespace. In practical terms, a regular account normally signals its own processes; signaling another account’s process generally requires appropriate privilege. Containers and other PID namespaces can make a process visible from one context but not another, so run inspection and signaling in the namespace where the target exists.

Common failures have distinct meanings:

  • “Operation not permitted” (EPERM): the caller lacks the required credentials or capability, or the namespace boundary prevents the operation.
  • “No such process” (ESRCH): the process already exited, the PID was never valid in this namespace, or a race occurred between inspection and signaling.
  • No visible change after SIGTERM: the program may be handling shutdown, stuck in an uninterruptible wait, or immediately restarted by a supervisor.

Do not respond to EPERM by automatically adding sudo. First verify that the process is the one you intend to stop and that terminating another user’s workload is authorized.

Race-safe signaling and version details

Shells commonly provide a builtin kill. To identify the external util-linux implementation, run:

/bin/kill --version

Current util-linux documentation describes PID:inode references for race-resistant signaling on Linux kernel 6.9 or later. It also documents --timeout, which sequences follow-up signals while tying them to the same process identity. These facilities are useful in automation where a PID could otherwise be reused between a graceful signal and a later force signal.

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

pkill can use a pidfd-based signaling path when it can obtain a process file descriptor. That reduces ambiguity compared with constructing a later command from a bare PID, but it does not remove the need to choose a safe pattern.

On systems without those identity-aware facilities, keep inspection and signaling as close together as possible. Do not save a PID in one script step, perform unrelated work for several minutes, and then send SIGKILL without checking the command and owner again. A newly created process may have inherited the old number.

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

Reliable workflows for common situations

A frozen game or graphical application

  1. Find the process with ps or pgrep -a, and confirm the owner and command line.
  2. Send kill -TERM PID.
  3. Wait while watching the same PID.
  4. If it remains and you have confirmed the identity again, send kill -KILL PID.
  5. Check for a restart by a launcher or service before assuming the signal failed.

Several instances of a server

  1. Preview with pgrep -a -u account pattern.
  2. If only one command line is intended, use pkill -f with a distinctive, quoted expression.
  3. If every instance for one account should stop, use killall -u account -i name.
  4. Inspect the result and logs rather than repeating a broad command.

A script that must escalate

Store and validate the process identity as close as possible to the signal operation. Prefer pidfd or the util-linux identity-aware features on systems that support them. If those are unavailable, re-run a precise inspection before escalation; never assume the original PID still belongs to the same program.

A process that will not disappear

First inspect its state rather than repeating kill -9. An uninterruptible wait can keep a task visible until an underlying I/O operation completes, and a zombie is already terminated but waiting for its parent to collect its status. In either case, another terminating signal may not change what you see. If a supervisor recreates the process, stopping the child alone will also appear ineffective because a replacement quickly receives a new PID.

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

Common mistakes to avoid

  • Using kill -9 first: SIGKILL prevents cleanup and can leave application state inconsistent.
  • Assuming a name identifies one process: launchers, workers and different users can share a command name.
  • Ignoring the 15-character limit: default pkill matching may not distinguish long names.
  • Using an unquoted full-command pattern: shell metacharacters can change the expression before pkill sees it.
  • Escalating from a stale PID: PID reuse can make a later command hit an unrelated process.
  • Expecting killall -w to prove identity: it polls once per second and has a replacement race.
  • Assuming success means shutdown: the signal may have been accepted while a supervisor immediately restarted the program.

Checklist before pressing Enter

  • Did you inspect the current PID, command, owner and process group?
  • Is the selector exact, or can it match launchers, helpers or another user’s instance?
  • Have you tried SIGTERM first?
  • Have you allowed enough time for normal cleanup?
  • Would SIGKILL risk losing saves, files, sockets or other state?
  • Could a supervisor restart the process?
  • Are you operating in the correct user and PID namespace?
  • If using killall -w, can you safely tolerate an indefinite wait?

The safest default remains simple: inspect, select narrowly, send SIGTERM, verify, and escalate only to a confirmed target when graceful shutdown has genuinely failed.

Frequently Asked Questions

How do I kill one process by PID?

Inspect the PID, then run kill PID or the explicit kill -TERM PID. Wait and verify that the same process has exited before considering kill -KILL PID.

What is the difference between kill, pkill and killall?

kill addresses a PID or process group. pkill selects processes with a pattern and filters such as user, parent, group or terminal. killall selects by command name and can signal every matching instance.

Should I always use kill -9?

No. SIGKILL cannot be caught or handled, so the program cannot save files, close sockets or clean up. Send SIGTERM first and use SIGKILL only for a confirmed process that will not shut down normally.

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

Why did pkill kill more than one process?

Its pattern is applied to every matching process, not just the first. The default name can also be broad, and it is limited to 15 characters. Preview with pgrep -a, then use -x, -f and identity filters deliberately.

Why did killall stop several users’ processes?

killall name matches the command name across the visible namespace. Add -u user, use an exact or narrower match, and consider -i for interactive confirmation.

What does kill -0 do?

Signal zero delivers no terminating signal. It checks whether the PID exists and whether your process would be permitted to signal it. It does not prove that the target is healthy or that the PID will not be reused later.

Why does killall -w wait forever?

The option checks roughly once per second and can wait indefinitely if the process ignores the signal, the signal has no effective result, or the process remains a zombie. A PID can also disappear and be replaced between checks.

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

What does Operation not permitted mean when killing a process?

The caller lacks the required user-ID relationship or CAP_KILL capability, or a namespace boundary prevents the operation. Verify ownership and namespace before adding privilege.

The Bottom Line

Inspect the current target, choose the narrowest selector, send SIGTERM, and verify the result. Reserve SIGKILL for a reconfirmed process whose graceful shutdown has failed, and treat broad pkill, killall and process-group commands as multi-process operations.

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.

Leave a Reply

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

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.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.