πŸ“œ Part of Pranav Kulkarni's technical portfolio Visit pranavkulkarni.org β†’
Lesson 1 Β· System Administration

Process Management

Learn to monitor, manage, and control running processes.

Viewing Processes

$ ps aux # List all 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 PID # Graceful termination (SIGTERM)
$ kill -9 PID # Force kill (SIGKILL)
$ killall nginx # Kill all by name
$ pkill -f "python script" # Kill by pattern

Background Jobs

$ command & # Run in background
$ 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).

# Custom ps output (great for triage)
$ 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 -TERM 1234 # graceful stop
$ 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?

# Command line + environment
$ 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.

$ nice -n 10 long_job.sh # start with lower CPU priority
$ sudo renice 15 -p 1234 # adjust running process
$ sudo ionice -c2 -n7 -p 1234 # lower disk I/O priority

Troubleshooting Playbook

  1. Is the system overloaded? Check uptime, load average, and memory.
  2. Who is using CPU/RAM? Use top or ps --sort=-pcpu/--sort=-pmem.
  3. Is it stuck in I/O? Look for D state and check disk latency/logs.
  4. Is it a service? Prefer systemctl to manage it (see next lesson).
$ uptime
$ free -h
$ top -o %CPU

βœ… Practice (15 minutes)

  • Start a background job and use jobs, fg, bg, and kill to control it.
  • Pick a running process and inspect /proc/<PID>/cmdline and its open files via lsof -p.
  • Use ps -eo ... --sort=-pcpu to find the top CPU consumer.