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

Find, list, and summarize running processes.

List processes with BSD format

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

bashANYpsinspectlisting
bash
ps aux

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

List processes with full format

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

bashANYpsinspectlisting
bash
ps -ef

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

List processes for a user

Filter processes by effective user and show full format.

bashANYpsuserfilter
bash
ps -u "$USER" -f

Filter processes by effective user and show full format.

Show one PID

Inspect a specific process by PID.

bashANYpspidfilter
bash
ps -p 1234 -f

Inspect a specific process by PID.

Show parent-child tree in ps

Render a process tree using ps output.

bashANYpstreehierarchy
bash
ps -ef --forest

Render a process tree using ps output.

Find PID by name

Return matching PIDs for a process name pattern.

bashANYpgreppidfind
bash
pgrep nginx

Return matching PIDs for a process name pattern.

Find process by full command line

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

bashANYpgrepfull-commandfind
bash
pgrep -af "python.*worker"

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

Find PID with pidof

List the PIDs of a program by executable name.

bashANYpidofpidfind
bash
pidof sshd

List the PIDs of a program by executable name.

Show process tree

Display process hierarchy with PIDs and arguments.

bashANYpstreetreehierarchy
bash
pstree -ap

Display process hierarchy with PIDs and arguments.

Custom ps columns

Build a custom process table and sort by CPU usage.

bashANYpscolumnssort
bash
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

List lightweight processes or threads.

bashANYpsthreads
bash
ps -eLf | head

List lightweight processes or threads.

Find oldest matching process

Return the oldest matching PID.

bashANYpgrepoldest
bash
pgrep -o sshd

Return the oldest matching PID.

Find newest matching process

Return the newest matching PID.

bashANYpgrepnewest
bash
pgrep -n sshd

Return the newest matching PID.

Filtering and Sorting

Focus on exactly the processes you need.

Sort by CPU

Show the most CPU-intensive processes first.

bashANYpssortcpu
bash
ps -eo pid,comm,%cpu,%mem --sort=-%cpu | head

Show the most CPU-intensive processes first.

Sort by memory

Show the most memory-intensive processes first.

bashANYpssortmemory
bash
ps -eo pid,comm,%mem,rss,vsz --sort=-%mem | head

Show the most memory-intensive processes first.

Filter by TTY

Show processes attached to a terminal.

bashANYpsttyfilter
bash
ps -t pts/0 -f

Show processes attached to a terminal.

Filter by parent PID

List child processes of a specific parent.

bashANYpsppidfilter
bash
ps --ppid 1 -f

List child processes of a specific parent.

Find process owned by user

Limit matches to one or more users.

bashANYpgrepuserfilter
bash
pgrep -u www-data nginx

Limit matches to one or more users.

Find process by session

Match processes in a session ID.

bashANYpgrepsession
bash
pgrep -s 1234

Match processes in a session ID.

Find process by terminal

Match processes running on a specific terminal.

bashANYpgreptty
bash
pgrep -t pts/0

Match processes running on a specific terminal.

Filter by state

Find processes in a given state, here zombies.

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

Find processes in a given state, here zombies.

Find process listening on port

Identify the process bound to a TCP port.

bashANYlsofportfind
bash
lsof -iTCP:8080 -sTCP:LISTEN -Pn

Identify the process bound to a TCP port.

Show process for listening sockets

List listening TCP sockets with process info.

bashANYsssocketprocess
bash
ss -lntp

List listening TCP sockets with process info.

Process Control and Signals

Terminate, pause, resume, and signal processes safely.

Send SIGTERM

Ask a process to terminate gracefully.

bashANYkillsignalterm
bash
kill 1234

Ask a process to terminate gracefully.

Force kill with SIGKILL

Immediately kill a process that is not responding.

bashANYkillsignalsigkill
bash
kill -9 1234

Immediately kill a process that is not responding.

Reload with SIGHUP

Commonly used to ask daemons to reload configuration.

bashANYkillsignalreload
bash
kill -HUP 1234

Commonly used to ask daemons to reload configuration.

Pause process with SIGSTOP

Suspend execution without terminating the process.

bashANYkillsignalstop
bash
kill -STOP 1234

Suspend execution without terminating the process.

Resume process with SIGCONT

Resume a stopped process.

bashANYkillsignalcontinue
bash
kill -CONT 1234

Resume a stopped process.

Signal by name

Signal all processes whose names match a pattern.

bashANYpkillsignalname
bash
pkill nginx

Signal all processes whose names match a pattern.

Signal by full command

Match against full command lines.

bashANYpkillsignalfull-command
bash
pkill -f "gunicorn: worker"

Match against full command lines.

Kill all processes for a user

Signal all processes owned by a user.

bashANYpkillusersignal
bash
pkill -u alice

Signal all processes owned by a user.

Kill all by executable name

Kill all processes that match an executable name.

bashANYkillallsignal
bash
killall node

Kill all processes that match an executable name.

List signal names

Print known signal names and numbers.

bashANYkillsignalsreference
bash
kill -l

Print known signal names and numbers.

Pipe pgrep into kill

Signal all matching PIDs found via pgrep.

bashANYpgrepxargskill
bash
pgrep -f "celery worker" | xargs kill -TERM

Signal all matching PIDs found via pgrep.

Kill process using a port

Kill the process that is using a TCP port.

bashANYfuserportkill
bash
fuser -k 8080/tcp

Kill the process that is using a TCP port.

Priority, Scheduling, and CPU Affinity

Adjust scheduling priority and pin workloads.

Start command with lower priority

Run a command with a niceness offset.

bashANYnicepriority
bash
nice -n 10 long-running-job

Run a command with a niceness offset.

Change process priority

Adjust niceness for an existing process.

bashANYrenicepriority
bash
renice 5 -p 1234

Adjust niceness for an existing process.

Show real-time scheduler

Inspect real-time scheduling policy and priority.

bashANYchrtscheduler
bash
chrt -p 1234

Inspect real-time scheduling policy and priority.

Set SCHED_FIFO policy

Assign a real-time FIFO scheduler to a process.

bashANYchrtschedulerrealtime
bash
sudo chrt -f -p 50 1234

Assign a real-time FIFO scheduler to a process.

Run command on selected CPUs

Pin a command to specific CPU cores.

bashANYtasksetcpu-affinity
bash
taskset -c 0,1 myserver

Pin a command to specific CPU cores.

Show or change affinity for PID

Inspect or update CPU affinity for an existing process.

bashANYtasksetcpu-affinity
bash
taskset -cp 0-3 1234

Inspect or update CPU affinity for an existing process.

Run with IO priority

Run a command with lower I/O priority.

bashANYioniceio-priority
bash
ionice -c2 -n7 updatedb

Run a command with lower I/O priority.

Change IO priority for PID

Set idle I/O scheduling for a running process.

bashANYioniceio-priority
bash
ionice -c3 -p 1234

Set idle I/O scheduling for a running process.

Set shell resource limit

Cap the number of user processes for the current shell.

bashANYulimitlimits
bash
ulimit -u 4096

Cap the number of user processes for the current shell.

Backgrounding and Daemonization

Keep commands running after you disconnect or background them safely.

Run command immune to hangups

Keep a process running after the shell exits.

bashANYnohupbackground
bash
nohup ./worker.sh > worker.log 2>&1 &

Keep a process running after the shell exits.

Start in a new session

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

bashANYsetsidsession
bash
setsid ./server.sh

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

Run inside screen

Use screen for a resumable terminal session.

bashANYscreenbackground
bash
screen -S myjob

Use screen for a resumable terminal session.

Run inside tmux

Use tmux for persistent terminal multiplexing.

bashANYtmuxbackground
bash
tmux new -s myjob

Use tmux for persistent terminal multiplexing.

Limit runtime with timeout

Terminate a command if it runs too long.

bashANYtimeoutcontrol
bash
timeout 30s ./script.sh

Terminate a command if it runs too long.

Measure elapsed time

Measure runtime of a command.

bashANYtimemeasurement
bash
time tar -czf backup.tgz /srv/data

Measure runtime of a command.

Repeat command with watch

Re-run a command periodically for live monitoring.

bashANYwatchmonitoring
bash
watch -n 2 "ps -eo pid,comm,%cpu --sort=-%cpu | head"

Re-run a command periodically for live monitoring.

Recommended next

No recommendations yet.