kill and pkill Commands in Linux: Syntax, Options & Signal Examples

kill sends a signal to a process when you know its PID; pkill matches processes by name or command line and signals them in bulk. Together they are the standard way to stop runaway jobs, reload daemons, or end test processes without rebooting.

Published

Updated

Read time 10 min read

Reviewed byDeepak Prasad

kill and pkill Commands in Linux: Syntax, Options & Signal Examples
About kill sends a signal to a process when you know its PID; pkill matches processes by name or command line and signals them in bulk. Together they are the standard way to stop runaway jobs, reload daemons, or end test processes without rebooting.
Tested on Ubuntu 25.04 (Plucky Puffin); procps-ng 4.0.4; kernel 7.0.0-27-generic
Package procps (apt/deb) · procps-ng (dnf/rpm)
Man page kill(1)
Privilege none for own processes; root for others' processes
Distros

GNU/Linux with procps / procps-ng (Ubuntu, Debian, Fedora, RHEL, and most distros).

Match processes before signalling: ps command cheat sheet.

Related guide

kill — quick reference

Send signals by PID

Use /bin/kill when you already have a process ID from ps, pgrep, or a job control listing. The shell built-in kill also handles job IDs (%1) but does not support --version.

When to use Command
Politely ask a process to exit (default SIGTERM) /bin/kill PID
Send SIGTERM by name /bin/kill -TERM PID
Force immediate stop when TERM is ignored (SIGKILL) /bin/kill -KILL PID
Check whether a PID exists without sending a signal /bin/kill -0 PID
Send hangup to reload many daemons (SIGHUP) /bin/kill -HUP PID

List and resolve signal names

When to use Command
List all signal names /bin/kill -l
Show the number for a signal name /bin/kill -l TERM
Show the name for a signal number /bin/kill -l 15

pkill — quick reference

Match and signal by name

pkill finds processes whose executable name matches the pattern, then sends the default SIGTERM unless you pass a signal.

When to use Command
Stop processes whose name matches sleep pkill sleep
Match the process name exactly (not substring) pkill -x sleep
Match the full command line (script path or args) pkill -f 'sleep 3600'
Print which PIDs were signalled pkill -e sleep
Count matches without sending a signal yet pkill -c sleep
Signal only the newest matching process pkill -n sleep
Signal only the oldest matching process pkill -o sleep
Send SIGTERM explicitly by number pkill -15 sleep
Send SIGKILL when TERM failed pkill -9 sleep

Filters and safety

When to use Command
Limit matches to a specific user pkill -u username sleep
Match only children of a parent PID pkill -P PPID
Show brief usage pkill --help
Show procps-ng version pkill --version

kill — command syntax

Synopsis from /bin/kill --help on Ubuntu 25.04 (procps-ng 4.0.4):

text
kill [options] <pid> [...]

pkill synopsis from pkill --help:

text
pkill [options] <pattern>

Signals are defined in signal(7). SIGTERM (15) lets a process clean up; SIGKILL (9) cannot be caught and should be a last resort. You may only signal other users' processes as root.


kill and pkill — command examples

Essential Stop one process by PID with SIGTERM

When you know the PID — from ps or $! after backgrounding a job — kill sends SIGTERM so the process can exit cleanly.

Start a harmless test process and stop it:

bash
sleep 3600 &
PID=$!
ps -p $PID -o pid,cmd
/bin/kill -TERM $PID
sleep 0.3
ps -p $PID 2>&1 || echo "PID gone"

Sample output:

text
PID CMD
  43831 sleep 3600
    PID TTY          TIME CMD
PID gone

SIGTERM is the default when you omit the signal name (/bin/kill $PID). Use this on lab sleep jobs or your own scripts — not on sshd or NetworkManager unless you intend to disrupt the session.

Essential Test whether a PID exists (kill -0)

kill -0 sends no signal. It exits zero if the process exists and you are allowed to signal it — useful in shell scripts before waiting or logging.

Run the commands:

bash
sleep 3600 &
PID=$!
/bin/kill -0 $PID && echo "process $PID exists"
/bin/kill $PID

Sample output:

text
process 43865 exists

After the process exits, the same test fails with a non-zero exit code and No such process.

Essential Stop processes by name with pkill

When you do not have a PID handy, pkill matches the process name (the comm field). -e echoes what was killed — helpful in scripts and labs.

Run the commands:

bash
sleep 3600 &
PID=$!
pkill -x sleep -e
sleep 0.2
ps -p $PID 2>&1 || echo "gone"

Sample output:

text
sleep killed (pid 43875)
gone

-x requires an exact name match so you do not accidentally hit mysleepd when you type sleep. Without -x, pkill sleep matches any process whose name contains sleep.

Common Match the full command line (-f)

When several python processes run different scripts, match the full command line with -f:

bash
sleep 3600 &
PID=$!
pkill -f '^sleep 3600$' -e
sleep 0.2
ps -p $PID 2>&1 || echo "gone"

Sample output:

text
sleep killed (pid 43905)
gone

Anchor the pattern (^…$) when you can — broad -f patterns can match your own shell or pkill line. Always verify with pgrep -af pattern before signalling on production hosts.

Common List signal names and numbers (-l)

Interview questions and daemon reload steps often refer to signal names; kill -l maps names to numbers.

Run the commands:

bash
/bin/kill -l TERM
/bin/kill -l 15
/bin/kill -l | head -n 2

Sample output:

text
15
TERM
HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT
CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS

Common signals: HUP (1) reload config, TERM (15) graceful stop, KILL (9) force stop.

Common Count matches before killing (-c)

Before sending a signal to every matching process, -c prints how many would match — a safety check when the pattern is broad.

Run the commands:

bash
sleep 3600 & sleep 3600 & sleep 3600 &
sleep 0.1
pkill -c sleep
pkill sleep

Sample output:

text
3

If the count is higher than expected, refine the pattern with -x or -f before signalling.

Advanced Kill only the newest match (-n)

When several identical workers run and only the latest misbehaves, -n signals the most recently started match.

Run the commands:

bash
sleep 3600 & OLD=$!
sleep 0.5
sleep 3600 & NEW=$!
echo "OLD=$OLD NEW=$NEW"
pkill -n sleep -e
ps -p $OLD -o pid 2>&1
ps -p $NEW 2>&1 || echo "NEW gone"
/bin/kill $OLD 2>/dev/null

Sample output:

text
OLD=43896 NEW=43898
sleep killed (pid 43898)
    PID
  43896
    PID TTY          TIME CMD
NEW gone

-o selects the oldest match instead. Clean up any remaining lab processes with pkill sleep when finished.

Advanced Error: No such process

Signalling a PID that already exited or never existed returns an error and exit code 1 — scripts should handle that.

Run the command:

bash
/bin/kill 99999999 2>&1
echo "exit=$?"

Sample output:

text
/bin/kill: (99999999): No such process
exit=1

Race conditions are common: another admin or the process itself may exit between your ps and kill. Re-check with kill -0 or ps -p PID if the result matters.


kill and pkill — when to use / when not

Use kill / pkill when Use something else when
  • You have a PID and need to send SIGTERM, SIGHUP, or SIGKILL
  • You want to stop all processes matching a name (pkill nginx)
  • You must match a script path or argument string (pkill -f)
  • You are ending your own test jobs or hung foreground work in a lab
  • You need to reload a daemon that respects SIGHUP
  • You need a table of processes first → ps or top
  • You want an interactive picker → top then k, or htop
  • You are stopping a systemd servicesystemctl stop UNIT
  • You need to kill by port → ss/lsof to find PID, then kill
  • You want to pause or resume (not terminate) → kill -STOP PID / kill -CONT PID

kill vs pkill vs killall

kill pkill killall
Target PID (or job ID in shell) Name / regex pattern Exact process name
Needs PID Yes No No
Full cmdline match No -f Varies by implementation
Portable Very Very (procps-ng) Linux; flags differ on BSD

Prefer kill when you already verified the PID. Prefer pkill when matching by name — always dry-run with pgrep -af or pkill -c first on shared systems.


Process workflow neighbours — list, filter, and service-level stops.

Command One line
kill / pkill Signal processes by PID or name (this page)
ps Snapshot process list and find PIDs
systemctl Stop managed services cleanly
kill hung SSH session End stuck terminal sessions

Browse the full index on the Linux commands cheat sheet.


kill and pkill — interview corner

What is the difference between SIGTERM and SIGKILL?

SIGTERM (15) asks a process to exit. The program can catch it, flush buffers, close connections, and shut down cleanly.

SIGKILL (9) forces immediate termination. The kernel removes the process; it cannot be caught or ignored.

Workflow: try kill PID or kill -TERM PID first; use kill -9 PID only when the process ignores TERM or is stuck in uninterruptible sleep.

A strong answer is:

"SIGTERM is a polite shutdown the process can handle; SIGKILL is non-ignorable and immediate. I send TERM first, then KILL if the process does not exit."

When do you use kill versus pkill?

kill needs a PID — you get that from ps, pgrep, systemd, or $!.

pkill takes a pattern and signals every matching process — faster when six worker processes share the same name.

pkill is convenient but riskier on shared hosts: a broad pattern can hit more than you intend. Use pkill -x for exact names or pgrep -af to preview.

A strong answer is:

"kill when I have a confirmed PID; pkill when I need to signal by process name. I preview matches with pgrep and prefer -x or -f for precision."

What does kill -0 do?

kill -0 PID sends no signal. It only checks whether the PID exists and whether you have permission to signal it. Exit code 0 means yes; non-zero means missing PID or permission denied.

Shell scripts use it to wait until a child has finished starting or to avoid errors when a PID file is stale.

A strong answer is:

"kill -0 is an existence check — no signal is delivered. Exit 0 means the process is there and signalable."

What does pkill -f match?

By default pkill compares the pattern to the process name (comm). -f compares against the full command line — argv[0] plus arguments.

That is how you target python /opt/app/worker.py without killing every Python interpreter. It is also easy to over-match; use anchored regex and verify with pgrep -af.

A strong answer is:

"Without -f, pkill matches the process name; with -f it matches the full command line — I use pgrep -af first to avoid killing the wrong PIDs."

What is the difference between the shell kill builtin and /bin/kill?

Bash provides a kill builtin so job IDs work (kill %1). The external /bin/kill from procps-ng is what man kill(1) documents — it supports --version and behaves the same for numeric PIDs.

In scripts that only use PIDs, either works. When documenting signals for interviews or portable scripts, refer to /bin/kill or kill after command kill to avoid builtin quirks.

A strong answer is:

"The shell builtin adds job control; /bin/kill is the procps binary documented in man kill. For PIDs both send signals — I use the binary in scripts when I need consistent --help output."


Troubleshooting

Symptom Likely cause Fix
No such process PID already exited Refresh with ps or pgrep
Operation not permitted Process owned by another user sudo /bin/kill PID
Process ignores TERM Bug, stuck I/O, or zombie parent Retry with -9; fix parent with ps -o ppid
pkill kills too much Broad pattern or missing -x pgrep -af pat; narrow with -f '^…$'
pkill does nothing Name mismatch ps -p PID -o comm,args; try -f
Cannot kill D state Uninterruptible sleep (often I/O) Fix underlying NFS/disk; reboot last resort

References

Rohan Timalsina

is a technical writer and Linux enthusiast who writes practical guides on Linux commands and system administration. He focuses on simplifying complex topics through clear explanations.