Linux Process Management: Monitoring and Controlling Processes
Learn to manage Linux processes effectively including monitoring tools, signals, priority control, background jobs, and automation with systemd.
Controlling Processes in Linux
When a system is compromised, malicious processes hide among legitimate ones. Knowing how to inspect, prioritize, and terminate processes gives you the ability to identify anomalies, stop attacks in progress, and keep your own tools running efficiently. This guide covers the practical skills you need to manage processes from the command line.
Prerequisites
Basic Linux command line knowledge. Familiarity with ps and top commands.
Process States
| State | Code | Description |
|-------|------|-------------|
| Running | R | Currently executing or in run queue |
| Sleeping | S | Waiting for an event (interruptible) |
| Uninterruptible Sleep | D | Waiting for I/O |
| Stopped | T | Paused by a signal |
| Zombie | Z | Terminated but not cleaned up by parent |
Viewing Processes
ps — Process Snapshot
ps aux # All processes with details
ps ux # Current user's processes
ps auxf # Process tree
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10 # Sort by memory
Output columns: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND.
top — Dynamic Process Viewer
top
Interactive keys: P (sort by CPU), M (sort by memory), k (kill process), u (filter by user), q (quit).
htop — Enhanced Viewer
sudo apt install htop
htop
Color-coded, mouse support, easier process management.
Process Signals
kill -1 PID # SIGHUP - Reload configuration
kill -2 PID # SIGINT - Interrupt (Ctrl+C)
kill -9 PID # SIGKILL - Force kill (cannot be ignored)
kill -15 PID # SIGTERM - Terminate gracefully (default)
kill -19 PID # SIGSTOP - Pause
kill -18 PID # SIGCONT - Resume
Sending Signals
kill -15 1234 # Kill by PID
pkill -9 firefox # Kill by name
killall -15 chrome # Kill by name pattern
pkill -u username # Kill all processes for a user
timeout 5 tail -f /var/log/syslog # Kill after timeout
Always try SIGTERM (15) first — allows clean shutdown. Use SIGKILL (9) only when a process does not respond.
Process Priority (Nice Values)
Values range from -20 (highest priority) to 19 (lowest).
nice -n 10 ./backup_script.sh # Start with lower priority
renice -n -5 -p 1234 # Change priority of running process (root only)
ps -eo pid,ni,cmd | sort -k2 # View priorities
Background and Foreground Jobs
nmap -sV 192.168.1.1 & # Run in background
# Ctrl+Z suspends current foreground job
jobs # List background jobs
fg %1 # Bring job to foreground
bg %1 # Send to background
nohup ./long_script.sh & # Continue after logout
disown %1 # Remove from job table
systemd Service Management
systemctl list-units --type=service # List all services
systemctl status ssh # Check service status
sudo systemctl start ssh # Start a service
sudo systemctl stop ssh # Stop a service
sudo systemctl restart ssh # Restart a service
sudo systemctl enable ssh # Enable at boot
sudo systemctl disable ssh # Disable at boot
journalctl -u ssh # View service logs
journalctl -u ssh -f # Follow service logs
Monitoring Resource Usage
sudo iotop # Disk I/O monitoring
sudo nethogs # Network usage per process
free -h # Memory usage
lsof -p 1234 # Open files for a process
lsof -i -P -n # Network connections
Real-World Examples
Finding resource hogs: ps aux --sort=-%mem | head -5
Monitoring user activity: ps -u username -o pid,cmd,etime
Detecting suspicious processes: Unusual names, hidden from ps, running from /tmp, high network I/O may indicate malware.
Killing unresponsive scans: pkill -9 nmap
Common Mistakes
Using kill -9 as first resort — always try SIGTERM first. Ignoring zombie processes. Running GUI tools without backgrounding (wireshark &). Not using cgroups for resource limits in production.
Best Practices
Use top/htop for interactive monitoring. Always SIGTERM before SIGKILL. Use systemd for long-running processes. Monitor resources proactively. Use ulimit -n to check file descriptor limits.
Related Tools
htop — Enhanced process viewer. atop — Advanced monitor with logging. glances — Cross-platform monitoring. lsof — List open files. strace — Trace system calls. perf — Linux profiling.
Related Articles
Summary
Linux process management involves viewing (ps,top, htop), sending signals (kill, pkill), controlling priority (nice, renice), managing jobs (&, jobs, fg, bg), and administering systemd services (systemctl, journalctl).