Process Management & /proc
A clean, SRE-focused mental model for debugging a slow or stuck service using only the CLI.
Intermediate ๐ Quick reference: Incident Response Mastery โ- Learn process states, especially D (uninterruptible) and Z (zombie)
- Use
ps,top, andkillwith the right signals - Read
/proc/<pid>/for status, limits, and open files - Walk the service troubleshooting decision tree once
Table of Contentsโ
- Process Lifecycle Concepts
- Core Process Commands
- /proc Filesystem
- Real Interview-Style Debug Flow
- Troubleshooting Decision Tree
- Deep Troubleshooting Scenarios
- Interview Q&A
A slow or stuck service gets triaged down one of three branches โ zombie/defunct, alive but blocked, or resource-starved โ and every branch gets confirmed through /proc before you decide whether to restart the parent, kill the process, or tune the resource it's starved of.
๐น Process Lifecycle Conceptsโ
PID / PPIDโ
- PID โ unique process ID
- PPID โ parent process ID (who started it)
๐ Helps trace process trees and restart chains.
Zombie Processโ
- Process finished execution but the parent didn't read its exit status.
- Shows as
Zinps. - Not consuming CPU, but leaks process table entries.
- Fix โ restart the parent or handle
wait()properly.
Orphan Processโ
- Parent dies โ child adopted by PID 1 (systemd).
- Usually harmless unless logic depends on the parent.
Daemonโ
- Background service (no terminal), e.g. web server, DB.
- Starts at boot, long-running, often managed by systemd.
๐น Core Process Commandsโ
ps auxโ
Snapshot of all processes. Key columns: USER PID %CPU %MEM STAT COMMAND
ps aux --sort=-%cpu | head
topโ
Real-time CPU/memory usage. Useful keys: P sort by CPU, M sort by memory, k kill process.
htopโ
Improved interactive top. Tree view, mouse support, easy kill.
atopโ
Advanced system monitor. Shows disk, network, memory, per-process history. ๐ Great for post-incident analysis.
pstreeโ
Visual parent-child relationship.
pstree -p
nice / reniceโ
Control CPU priority. Range: -20 (highest priority) โ 19 (lowest).
nice -n 10 myscript.sh
renice 5 -p 1234
kill / killallโ
Send signals to processes.
kill -15 PID # graceful stop
kill -9 PID # force kill
killall nginx # by name
pgrepโ
Find PID by process name.
pgrep -fl java
๐น /proc Filesystem (Real Gold for SREs)โ
Linux exposes live process internals here.
/proc/<pid>/statusโ
Human-readable metadata: state, memory usage, threads, parent, signals.
/proc/<pid>/limitsโ
Resource limits: max open files, max processes, memory limits. ๐ Crucial when a service crashes under load.
/proc/<pid>/fdโ
All open file descriptors (files, sockets, pipes).
ls -l /proc/1234/fd
๐ Detect file leaks or stuck network connections.
๐น Real Interview-Style Debug Flowโ
If a service is slow:
1๏ธโฃ Find the process
pgrep -fl service_name
2๏ธโฃ Check CPU/memory
top -p PID
3๏ธโฃ Inspect parent + threads
pstree -p PID
cat /proc/PID/status
4๏ธโฃ Check resource exhaustion
cat /proc/PID/limits
ls /proc/PID/fd | wc -l
5๏ธโฃ Lower priority or restart safely
renice 10 -p PID
kill -15 PID
๐ณ Linux Service Troubleshooting Decision Tree (CLI Only)โ
1๏ธโฃ Service is DOWNโ
Step 1 โ Is process running?
pgrep -fl service_name
ps aux | grep service_name
โก Not running โ check logs + restart. โก Running โ go deeper.
Step 2 โ Check parent + restart loop
pstree -p <PID>
โก Rapid respawns โ crash loop. โก No parent supervision โ config issue.
Step 3 โ Check logs
tail -f /var/log/service.log
2๏ธโฃ Service is SLOWโ
CPU high?
top -p <PID>
โก Yes โ CPU bottleneck. โก No โ check memory / I/O / limits.
Memory issue?
cat /proc/<PID>/status | grep Vm
File descriptor exhaustion?
ls /proc/<PID>/fd | wc -l
cat /proc/<PID>/limits
Thread explosion?
ps -T -p <PID>
3๏ธโฃ Service NOT STOPPINGโ
Check process state
ps -o pid,state,cmd -p <PID>
Dโ uninterruptible I/O waitZโ zombieRโ CPU loop
โก Try graceful kill โ force kill if safe.
4๏ธโฃ System Resource Exhaustionโ
ps aux | wc -l # too many processes
ls /proc/<PID>/fd # open file leak
uptime # load spike
๐ง Deep Troubleshooting Scenarios (Interview-Level)โ
โ Scenario 1: High CPU, Service Not Respondingโ
Symptoms: 100% CPU, requests timing out. Approach: identify culprit process โ check thread usage โ inspect parent and restart behavior.
top
ps -T -p <PID>
pstree -p <PID>
Answer Logic: Likely an infinite loop, retry storm, or heavy computation thread. Mitigate by reducing workers, renice, or restart.
โ Scenario 2: Service Slow, CPU Low, Memory Normalโ
Symptoms: latency high, CPU idle. Approach: check blocking resources.
ls /proc/<PID>/fd | wc -l
cat /proc/<PID>/limits
ps -o state,pid,cmd -p <PID>
Answer Logic: Most likely I/O wait, file descriptor exhaustion, or external dependency slowness.
โ Scenario 3: Service Randomly Crashes Under Loadโ
Approach: check resource limits.
cat /proc/<PID>/limits
dmesg | tail
Answer Logic: Common causes โ too many open files, memory limit exceeded, OOM killer. Mitigation: increase ulimit, optimize resource usage.
โ Scenario 4: Many Zombie Processesโ
ps aux | grep Z
pstree -p
Answer Logic: Parent not collecting exit status โ bug in process management. Restart the parent service.
โ Scenario 5: System Suddenly Slowโ
uptime
top
ps aux --sort=-%mem | head
Answer Logic: Check load average vs CPU cores โ if load >> cores โ resource saturation (CPU, disk, or lock contention).
โ Scenario 6: Cannot Kill Processโ
ps -o pid,state,cmd -p <PID>
Answer Logic: If state = D โ stuck in kernel I/O โ only reboot or fix the underlying disk/network issue resolves it.
๐ฏ SRE Interview Golden Lineโ
"When troubleshooting, I first identify whether the issue is CPU, memory, I/O, or limits related. Then I inspect process state via
/procand validate parent-child relationships before taking corrective action."
That sentence alone signals SRE maturity.
๐ฏ Interview Q&Aโ
Process Lifecycleโ
Q1. What is PID and PPID? Why important? PID uniquely identifies a process. PPID shows its parent. Used to trace service spawning, crashes, and supervision trees.
Q2. What is a zombie process?
Completed process whose parent hasn't read exit status. State = Z. Fix by restarting the parent or correcting wait() handling.
Q3. What is an orphan process? Parent dies โ child adopted by init/system manager. Usually safe but indicates parent failure.
Q4. What is a daemon? Background long-running service detached from a terminal (e.g. web server). Starts at boot and handles system tasks.
Commandsโ
Q5. Difference between ps, top, htop?
psโ static snapshottopโ real-time monitoringhtopโ interactive, tree view, easier control
Q6. How do you find top CPU-consuming processes?
ps aux --sort=-%cpu | head
top
Q7. How do you change process priority?
Start with nice, modify using renice.
Q8. SIGTERM vs SIGKILL?
15โ graceful shutdown9โ force kill, no cleanup
Q9. How to kill by name instead of PID?
killall process_name
pkill process_name
Q10. How to find a process PID quickly?
pgrep -fl process_name
Q11. Why use pstree?
To visualize parent-child hierarchy and detect runaway forks.
/proc Filesystemโ
Q12. What is /proc in Linux?
Virtual filesystem exposing real-time kernel and process data.
Q13. What can you check in /proc/<pid>/status?
Process state, memory, threads, signals, parent PID.
Q14. Why check /proc/<pid>/limits?
To diagnose crashes due to file descriptor or resource limits.
Q15. What is /proc/<pid>/fd used for?
Lists open files/sockets โ helps detect leaks or connection exhaustion.
Scenario-Based (Most Important for SRE3)โ
Q16. Service is slow but CPU low. What do you check? Open files, memory usage, threads, blocked I/O, limits.
Q17. Service not stopping after kill?
Check state via ps. If uninterruptible sleep โ I/O wait. Use SIGKILL only if safe.
Q18. Too many processes created suddenly. Why? Fork bomb, retry loop, crash loop, misconfigured worker pool.
Q19. System running out of file descriptors. How to confirm?
Check /proc/<pid>/limits and count /proc/<pid>/fd.
Q20. First 5 commands when a Linux service hangs?
top, ps aux, pstree, lsof (or fd), check /proc.
Summaryโ
- ๐ก A running process is not a healthy process โ always check state (
D/Z/R), not just existence. - ๐ฅ
/proc/<pid>/limits+/proc/<pid>/fdis the fastest way to confirm FD exhaustion before it becomes an outage. - โ ๏ธ State
D(uninterruptible I/O wait) cannot be killed withSIGKILLโ you must fix the underlying disk/network issue. - โ Zombies are fixed by fixing the parent process, never the zombie itself.
See Alsoโ
- Filesystem & Storage Playbook โ the deleted-file-still-open and disk-full scenarios referenced above
- Linux Kernel Fundamentals โ system calls, context switching, and
fork()/exec()internals - Incident Simulation Labs โ hands-on labs for zombies, FD leaks, and CPU hogs
- Linux Debugging Reference โ where process management fits in the full toolset