Process Management
Learn to monitor, manage, and control running processes.
Viewing Processes
$ ps aux | grep nginx # Find specific process
$ top # Real-time process monitor
$ htop # Enhanced process viewer
$ pgrep -l nginx # Find process by name
Managing Processes
$ kill -9 PID # Force kill (SIGKILL)
$ killall nginx # Kill all by name
$ pkill -f "python script" # Kill by pattern
Background Jobs
$ nohup command & # Persist after logout
$ jobs # List background jobs
$ fg %1 # Bring job 1 to foreground
$ bg %1 # Resume job 1 in background
Core Concepts: PID, PPID, and States
A process is a running program instance. It has a PID (process ID) and usually a PPID (parent PID).
Linux represents process metadata in /proc/<PID>.
Common process states youβll see in ps/top:
R (running), S (sleeping), D (uninterruptible I/O sleep),
Z (zombie), T (stopped).
$ ps -eo pid,ppid,stat,pcpu,pmem,etime,cmd --sort=-pcpu | head
# Process tree
$ pstree -ap | head
Signals: stop, reload, terminate
Signals are how you communicate with processes. SIGTERM (15) asks a process to exit gracefully.
SIGKILL (9) forcibly stops it (last resort). Many daemons support SIGHUP to reload config.
$ kill -HUP 1234 # reload config (daemon-dependent)
$ kill -KILL 1234 # force stop (avoid if possible)
# List signals
$ kill -l | head
Rule of thumb
Use SIGTERM first. If a process wonβt die, investigate why (I/O hang, kernel wait) before using SIGKILL.
Inspecting a Process
When something is misbehaving, you want to answer: what is it, who started it, what files/sockets does it use?
$ tr '\\0' ' ' < /proc/1234/cmdline
$ cat /proc/1234/environ | tr '\\0' '\\n' | head
# Open files and network sockets
$ sudo lsof -p 1234 | head
$ ss -tulpn | head
Priorities: nice and ionice
If a batch job is starving production traffic, lower its priority instead of killing it.
$ sudo renice 15 -p 1234 # adjust running process
$ sudo ionice -c2 -n7 -p 1234 # lower disk I/O priority
Troubleshooting Playbook
- Is the system overloaded? Check
uptime, load average, and memory. - Who is using CPU/RAM? Use
toporps --sort=-pcpu/--sort=-pmem. - Is it stuck in I/O? Look for
Dstate and check disk latency/logs. - Is it a service? Prefer
systemctlto manage it (see next lesson).
$ free -h
$ top -o %CPU
β Practice (15 minutes)
- Start a background job and use
jobs,fg,bg, andkillto control it. - Pick a running process and inspect
/proc/<PID>/cmdlineand its open files vialsof -p. - Use
ps -eo ... --sort=-pcputo find the top CPU consumer.