The essentials
Quick reference
One focused task per row. Jump to the related section for complete, working examples.
| Use | Syntax | Examples |
|---|---|---|
| List all processes | ps -ef | View examples |
| List your processes | ps -u "$USER" -o pid,ppid,stat,%cpu,%mem,comm | View examples |
| Inspect one PID | ps -p 4242 -o pid,ppid,user,stat,lstart,cmd | View examples |
| Show a process tree | ps -ef --forest | View examples |
| Monitor processes live | top | View examples |
| Find an exact name | pgrep -a -x nginx | View examples |
| Search full commands | pgrep -a -u "$USER" -f "python3 -m http.server" | View examples |
| Start a background job | python3 -m http.server 8000 >server.log 2>&1 & | View examples |
| Capture the latest PID | server_pid=$! | View examples |
| List shell jobs | jobs -l | View examples |
| Resume in foreground | fg %1 | View examples |
| Resume in background | bg %1 | View examples |
| Wait for a child process | wait "$server_pid" | View examples |
| Keep a command running | nohup python3 -m http.server 8000 >server.log 2>&1 & | View examples |
| Request termination | kill -TERM 4242 | View examples |
| Force termination | kill -KILL 4242 | View examples |
| Signal an exact name | pkill -TERM -x nginx | View examples |
| Start with lower priority | nice -n 10 gzip archive.tar | View examples |
| Change process priority | renice -n 5 -p 4242 | View 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
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.
ps -ef
ps -ef --forest 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.
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.
top Note: Press q to leave top; field availability and keyboard commands vary slightly by implementation.
pgrep -a -x nginx
pgrep -a -u "$USER" -f "python3 -m http.server" 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.
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.
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.
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.
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.
python3 -m http.server 8000 >server.log 2>&1 &
server_pid=$!
wait "$server_pid" 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.
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.
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.
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.
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.
nice -n 10 gzip archive.tar ps -p 4242 -o pid,ni,comm
renice -n 5 -p 4242
ps -p 4242 -o pid,ni,comm Sources and further reading
References
Authoritative documentation used to verify and expand this cheat sheet.
- procps-ng via Linux man-pagesps(1) — report a snapshot of the current processesman7.org
- procps-ng via Linux man-pagestop(1) — display Linux processesman7.org
- procps-ng via Linux man-pagespgrep(1) — look up, signal, or wait for processesman7.org
- Linux man-pages projectsignal(7) — overview of signalsman7.org
- 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.



