This guide covers essential commands and concepts for managing processes in a Linux system: how to view, control, prioritize, and terminate running tasks.
ps — Process SnapshotSyntax:
ps [options]
Examples:
ps # Show current shell's processes
ps aux # Show all running processes
ps -ef # Full-format listing
ps -u username # Processes by specific user
top — Real-Time Process Viewertop
P to sort by CPU, M for memoryk → Kill processq → Quithtop — Interactive Process Monitor (Enhanced Top)htop
(Install with sudo apt install htop if not present)
kill — Terminate by PIDSyntax:
kill [signal] PID
Examples:
kill 1234 # Send SIGTERM (default)
kill -9 1234 # Force kill (SIGKILL)
killall — Terminate by Namekillall firefox
killall -9 apache2
nice — Start Process with PrioritySyntax:
nice -n [value] command
Example:
nice -n 10 longtask.sh # Lower priority
-20 (highest) to 19 (lowest)renice — Change Priority of Running ProcessSyntax:
renice [value] -p PID
Example:
renice +5 -p 1234
fg, bg, jobs — Foreground/Background ControlCtrl + Z → Pause (suspend) current processbg → Resume in backgroundfg → Bring back to foregroundjobs → List background/paused processes| Command | Description | Example |
|---|---|---|
ps aux |
View all processes | ps aux \| grep nginx |
top |
Monitor live system usage | top |
htop |
Interactive process viewer | htop |
kill |
Kill process by PID | kill -9 1234 |
killall |
Kill process by name | killall firefox |
nice |
Launch with adjusted priority | nice -n 10 script.sh |
renice |
Change priority of running process | renice +5 -p 4567 |
fg, bg |
Foreground/background job control | fg, bg, jobs |
pgrep to get PIDs by name:pgrep apache2
kill -9 unless necessary — it skips cleanup.htop or top to find high-resource processes quickly.Linux offers robust tools to view, control, prioritize, and terminate processes. Mastering these helps manage system resources efficiently and troubleshoot performance issues with ease.