Linux Processes Cheat Sheet

Comprehensive Linux process inspection, control, scheduling, and backgrounding workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Process Inspection Basics
List processes with BSD format
ps aux

# Show all processes with user, CPU, memory, and command columns.

List processes with full format
ps -ef

# Show all processes with PID, PPID, start time, and command.

List processes for a user
ps -u "$USER" -f

# Filter processes by effective user and show full format.

Show one PID
ps -p 1234 -f

# Inspect a specific process by PID.

Show parent-child tree in ps
ps -ef --forest

# Render a process tree using ps output.

Find PID by name
pgrep nginx

# Return matching PIDs for a process name pattern.

Find process by full command line
pgrep -af "python.*worker"

# Match against the full command line and print PID plus command.

Find PID with pidof
pidof sshd

# List the PIDs of a program by executable name.

Show process tree
pstree -ap

# Display process hierarchy with PIDs and arguments.

Custom ps columns
ps -eo pid,ppid,user,%cpu,%mem,stat,start,time,cmd --sort=-%cpu

# Build a custom process table and sort by CPU usage.

Show threads with ps
ps -eLf | head

# List lightweight processes or threads.

Find oldest matching process
pgrep -o sshd

# Return the oldest matching PID.

Find newest matching process
pgrep -n sshd

# Return the newest matching PID.

## Filtering and Sorting
Sort by CPU
ps -eo pid,comm,%cpu,%mem --sort=-%cpu | head

# Show the most CPU-intensive processes first.

Sort by memory
ps -eo pid,comm,%mem,rss,vsz --sort=-%mem | head

# Show the most memory-intensive processes first.

Filter by TTY
ps -t pts/0 -f

# Show processes attached to a terminal.

Filter by parent PID
ps --ppid 1 -f

# List child processes of a specific parent.

Find process owned by user
pgrep -u www-data nginx

# Limit matches to one or more users.

Find process by session
pgrep -s 1234

# Match processes in a session ID.

Find process by terminal
pgrep -t pts/0

# Match processes running on a specific terminal.

Filter by state
ps -e -o pid,stat,cmd | awk '$2 ~ /^Z/ {print}'

# Find processes in a given state, here zombies.

Find process listening on port
lsof -iTCP:8080 -sTCP:LISTEN -Pn

# Identify the process bound to a TCP port.

Show process for listening sockets
ss -lntp

# List listening TCP sockets with process info.

## Process Control and Signals
Send SIGTERM
kill 1234

# Ask a process to terminate gracefully.

Force kill with SIGKILL
kill -9 1234

# Immediately kill a process that is not responding.

Reload with SIGHUP
kill -HUP 1234

# Commonly used to ask daemons to reload configuration.

Pause process with SIGSTOP
kill -STOP 1234

# Suspend execution without terminating the process.

Resume process with SIGCONT
kill -CONT 1234

# Resume a stopped process.

Signal by name
pkill nginx

# Signal all processes whose names match a pattern.

Signal by full command
pkill -f "gunicorn: worker"

# Match against full command lines.

Kill all processes for a user
pkill -u alice

# Signal all processes owned by a user.

Kill all by executable name
killall node

# Kill all processes that match an executable name.

List signal names
kill -l

# Print known signal names and numbers.

Pipe pgrep into kill
pgrep -f "celery worker" | xargs kill -TERM

# Signal all matching PIDs found via pgrep.

Kill process using a port
fuser -k 8080/tcp

# Kill the process that is using a TCP port.

## Priority, Scheduling, and CPU Affinity
Start command with lower priority
nice -n 10 long-running-job

# Run a command with a niceness offset.

Change process priority
renice 5 -p 1234

# Adjust niceness for an existing process.

Show real-time scheduler
chrt -p 1234

# Inspect real-time scheduling policy and priority.

Set SCHED_FIFO policy
sudo chrt -f -p 50 1234

# Assign a real-time FIFO scheduler to a process.

Run command on selected CPUs
taskset -c 0,1 myserver

# Pin a command to specific CPU cores.

Show or change affinity for PID
taskset -cp 0-3 1234

# Inspect or update CPU affinity for an existing process.

Run with IO priority
ionice -c2 -n7 updatedb

# Run a command with lower I/O priority.

Change IO priority for PID
ionice -c3 -p 1234

# Set idle I/O scheduling for a running process.

Set shell resource limit
ulimit -u 4096

# Cap the number of user processes for the current shell.

## Backgrounding and Daemonization
Run command immune to hangups
nohup ./worker.sh > worker.log 2>&1 &

# Keep a process running after the shell exits.

Start in a new session
setsid ./server.sh

# Start a process in a new session detached from the terminal.

Run inside screen
screen -S myjob

# Use screen for a resumable terminal session.

Run inside tmux
tmux new -s myjob

# Use tmux for persistent terminal multiplexing.

Limit runtime with timeout
timeout 30s ./script.sh

# Terminate a command if it runs too long.

Measure elapsed time
time tar -czf backup.tgz /srv/data

# Measure runtime of a command.

Repeat command with watch
watch -n 2 "ps -eo pid,comm,%cpu --sort=-%cpu | head"

# Re-run a command periodically for live monitoring.

Recommended next

No recommendations yet.