Bash 5 reference · Text and System Tools

ps and kill (Linux command)

List processes with ps and send signals with kill: SIGTERM to ask a process to stop, SIGKILL only as a last resort.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

ps [aux|-ef|-o FIELDS -p PID]   kill [-SIGNAL] PID   pgrep / pkill PATTERN

Parameters

ParameterDescription
ps -o pid,args -p PID Chosen columns for one process.
kill PID Send SIGTERM.
kill -9 PID SIGKILL: no cleanup.
kill -0 PID Check whether a process exists.
pkill -P PID Only children of PID: safer than matching with -f.

Examples

Inspect and stop a process
sleep 30 &
pid=$!
ps -o args= -p "$pid"
kill "$pid"; wait "$pid" 2>/dev/null; echo "exit status $? (143 = SIGTERM)"

Output

sleep 30
exit status 143 (143 = SIGTERM)

Run this on your computer — see “Get Started” for setup.

Find and stop this shell's children
sleep 60 & sleep 60 &
pgrep -c -P $$ sleep
pkill -P $$ sleep; wait 2>/dev/null; echo stopped

Output

2
stopped

Run this on your computer — see “Get Started” for setup.

Was this page helpful?