The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
List all processesps -efView examples
List your processesps -u "$USER" -o pid,ppid,stat,%cpu,%mem,commView examples
Inspect one PIDps -p 4242 -o pid,ppid,user,stat,lstart,cmdView examples
Show a process treeps -ef --forestView examples
Monitor processes livetopView examples
Find an exact namepgrep -a -x nginxView examples
Search full commandspgrep -a -u "$USER" -f "python3 -m http.server"View examples
Start a background jobpython3 -m http.server 8000 >server.log 2>&1 &View examples
Capture the latest PIDserver_pid=$!View examples
List shell jobsjobs -lView examples
Resume in foregroundfg %1View examples
Resume in backgroundbg %1View examples
Wait for a child processwait "$server_pid"View examples
Keep a command runningnohup python3 -m http.server 8000 >server.log 2>&1 &View examples
Request terminationkill -TERM 4242View examples
Force terminationkill -KILL 4242View examples
Signal an exact namepkill -TERM -x nginxView examples
Start with lower prioritynice -n 10 gzip archive.tarView examples
Change process priorityrenice -n 5 -p 4242View examples

Treat process management as an inspect-then-act workflow. Identify the exact PID, owner, and command first; distinguish shell jobs from system-wide processes; and request graceful termination with SIGTERM before considering a forceful signal.

Step by step

Detailed examples

01

Inspect process identity and relationships

ps reports a point-in-time snapshot rather than a continuously refreshed view. Choose explicit output fields when scripting or comparing processes, and use PID, parent PID, owner, state, and full command together to confirm the target. Process IDs can be reused after a process exits, so avoid acting on stale observations.

System-wide snapshot and process tree
ps -ef
ps -ef --forest
Current user and one selected PID
ps -u "$USER" -o pid,ppid,stat,%cpu,%mem,comm
ps -p 4242 -o pid,ppid,user,stat,lstart,cmd

Note: The sample PID may not exist on a particular machine; replace it only after identifying the intended process.

Back to quick reference ↑
02

Monitor activity and find precise matches

Use top for an interactive, repeatedly updated view and pgrep for scriptable process selection. pgrep normally matches the process name, while -f matches the full command line. Add exact-name and owner constraints whenever possible because a broad pattern may select unrelated processes.

Open the live process monitor
top

Note: Press q to leave top; field availability and keyboard commands vary slightly by implementation.

Find a service or development server
pgrep -a -x nginx
pgrep -a -u "$USER" -f "python3 -m http.server"
Back to quick reference ↑
03

Start a background process and retain its PID

An ampersand makes a pipeline asynchronous in the current shell. Redirect standard output and error when the background command should not keep writing over the prompt, then capture $! immediately before another background command can replace it. A shell job and an operating-system process are related concepts but use different identifiers.

Start and identify a local test server
python3 -m http.server 8000 >server.log 2>&1 &
server_pid=$!
printf 'server PID: %s\n' "$server_pid"

Note: The server exposes the current directory over HTTP; run it only in a directory whose contents are safe to serve.

Back to quick reference ↑
04

Move interactive jobs between foreground and background

Bash job control tracks pipelines started by the current interactive shell. jobs displays that shell-local table, fg gives a job terminal control, and bg resumes a stopped job asynchronously. Job specifications such as %1 are not process IDs and may change as jobs finish.

Inspect and resume job 1
jobs -l
bg %1
fg %1

Note: Use Ctrl+Z to suspend the current foreground job before resuming it with bg; Ctrl+C instead sends an interrupt signal.

Back to quick reference ↑
05

Wait for children or survive a terminal hangup

wait collects the completion status of a child process started by the current shell. nohup changes the command's hangup-signal disposition, but it does not automatically manage logs, restart failures, or turn a program into a production service. Use a service manager for long-lived supervised workloads.

Wait for the saved server process
python3 -m http.server 8000 >server.log 2>&1 &
server_pid=$!
wait "$server_pid"
Start a hangup-resistant test server
nohup python3 -m http.server 8000 >server.log 2>&1 &

Note: nohup does not detach every inherited resource; explicitly redirect input too when the program might read from the terminal.

Back to quick reference ↑
06

Signal the narrowest verified target

kill sends a signal rather than necessarily killing immediately. SIGTERM is the normal request to exit and permits cleanup; SIGKILL cannot be caught, blocked, or handled and should be a last resort. pkill selects potentially many processes, so preview the same criteria with pgrep before sending a signal by name.

Graceful then forceful PID handling
ps -p 4242 -o pid,user,stat,cmd
kill -TERM 4242
# After waiting and verifying that the same target is still running:
kill -KILL 4242

Note: Do not copy a PID from an old log or terminal without verifying it; the kernel may have assigned that number to a different process.

Preview and signal one exact process name
pgrep -a -x nginx
pkill -TERM -x nginx

Note: Permissions restrict which processes a user may signal, and an exact name can still match several worker processes.

Back to quick reference ↑
07

Adjust CPU scheduling priority carefully

A higher nice value generally means lower CPU scheduling priority. nice chooses the initial value for a new command, while renice changes a running process. Ordinary users can usually lower priority but need additional privilege to raise it, and niceness does not impose a hard CPU limit.

Lower priority for compression work
nice -n 10 gzip archive.tar
Inspect and change one running process
ps -p 4242 -o pid,ni,comm
renice -n 5 -p 4242
ps -p 4242 -o pid,ni,comm
Back to quick reference ↑

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. procps-ng via Linux man-pagesps(1) — report a snapshot of the current processesman7.org
  2. procps-ng via Linux man-pagestop(1) — display Linux processesman7.org
  3. procps-ng via Linux man-pagespgrep(1) — look up, signal, or wait for processesman7.org
  4. Linux man-pages projectsignal(7) — overview of signalsman7.org
  5. GNU ProjectJob Controlgnu.org

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback