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. For advanced navigation keys, custom meter meters, and process tree viewing, consult our in-depth htop command reference.
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
To search processes by name and send targeted termination signals without looking up individual PIDs, explore our comprehensive guides for killall, pkill, and pattern searching with pgrep.
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
For scheduling priority adjustment and Completely Fair Scheduler (CFS) behavior, see our detailed technical guides on starting processes with nice and adjusting running processes with renice.
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
For mastering interactive shell job control and session decoupling, read our dedicated references on monitoring active shell tasks with jobs, bringing tasks forward with fg, backgrounding paused jobs with bg, and immunity to SIGHUP terminal disconnections with nohup.
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
For comprehensive administration guides on managing service lifecycles, explore starting services with systemctl start, stopping daemons with systemctl stop, restarting processes with systemctl restart, configuring boot persistence with systemctl enable, and disabling automated startup with systemctl disable. To monitor running status, cgroup resource utilization, and recent log outputs, see systemctl status, and to inspect loaded systemd units across the operating system, consult systemctl list-units. For compatibility with legacy SysV init scripts, see our service reference, and for structured querying of systemd journal logs, explore journalctl.
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).
Knowledge Check
ps aux?Frequently Asked Questions
Continue Learning
Bash Scripting Basics: Automate Tasks Like a Pro
Learn Bash scripting from scratch covering variables, conditionals, loops, functions, error handling, and practical automation scripts for cybersecurity.
Linux · BeginnerCommand Line Essentials: Mastering the Terminal for Security Work
Essential command line skills for cybersecurity professionals including navigation, text processing, scripting, and automation.
Linux · BeginnerLinux Package Management: APT, DPKG, and Beyond
Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.
Linux · BeginnerSSH Fundamentals: Secure Remote Access and Administration
Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.
Related Security Tools
Commix
Commix (Command Injection Exploiter) is an automated tool designed to test, detect, and exploit command injection vulnerabilities in web applications, facilitating automated OS shell access.
Post ExploitationEvil-WinRM
Learn how to use Evil-WinRM, a Ruby-based client for the Windows Remote Management (WinRM) protocol. This guide covers installation, your first connection, password, pass-the-hash and Kerberos authentication, file transfers and script execution, all for use in authorized lab environments.
ExploitationMSFVenom
MSFVenom is a standalone payload generator and encoder utility within the Metasploit Framework, first introduced in Metasploit 4.0 (2015) to replace the legacy msfpayload and msfencode tools with a single unified interface. It enables security professionals, penetration testers, and students to create, customize, and encode payloads for multiple platforms including Windows, Linux, macOS, Android, and PHP. MSFVenom is widely used in CTF competitions, security training labs, authorized penetration testing engagements, and red team operations to generate reverse shells, Meterpreter payloads, shellcode, and encoded executables. Understanding MSFVenom helps both offensive and defensive security professionals learn payload construction techniques, encoding methods, and detection strategies used in modern cybersecurity.
Information GatheringSMBClient
Learn how to use SMBClient on Kali Linux: install Samba's FTP-like SMB/CIFS client, list shares, connect as a guest or with credentials, browse folders, and upload or download files on Windows, Samba, or NAS devices. For authorized assessments, check ports 139/445 with Nmap before testing share permissions.