Skip to main content

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 this in 10 minutes10 min
  1. Learn process states, especially D (uninterruptible) and Z (zombie)
  2. Use ps, top, and kill with the right signals
  3. Read /proc/<pid>/ for status, limits, and open files
  4. Walk the service troubleshooting decision tree once

Table of Contentsโ€‹

  1. Process Lifecycle Concepts
  2. Core Process Commands
  3. /proc Filesystem
  4. Real Interview-Style Debug Flow
  5. Troubleshooting Decision Tree
  6. Deep Troubleshooting Scenarios
  7. Interview Q&A

๐Ÿงญ Mental modelBranching triage for a stuck or slow processA slow or stuck service is triaged down one of three branches โ€” zombie, blocked-but-alive, or resource-starved โ€” all of which get confirmed through /proc before deciding whether to restart, kill, or tune it.Service Acting Slowor unresponsiveZombie / defunct?ps shows Z stateAlive but stuck?blocked on I/O or lockResource starved?CPU / memory / FDs/proc Inspectionstatus, fd, stackAct: Restart, Kill, or Tunebased on the confirmed cause

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 Z in ps.
  • 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 wait
  • Z โ†’ zombie
  • R โ†’ 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 /proc and 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 snapshot
  • top โ†’ real-time monitoring
  • htop โ†’ 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 shutdown
  • 9 โ†’ 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>/fd is the fastest way to confirm FD exhaustion before it becomes an outage.
  • โš ๏ธ State D (uninterruptible I/O wait) cannot be killed with SIGKILL โ€” you must fix the underlying disk/network issue.
  • โœ… Zombies are fixed by fixing the parent process, never the zombie itself.

See Alsoโ€‹