Linux Process Management: Control Running Applications
Manage Linux processes. View running processes, manage foreground/background, signals, priority, process groups, systemd services, resource limits.
On this page
A process is a running instance of a program. Linux runs dozens of processes simultaneously (services, daemons, user applications). Process management means viewing, controlling, prioritizing, and terminating processes. Essential for system administration, troubleshooting, and optimization.
Process Basics
Process anatomy:**
- PID (Process ID): Unique number identifying each process
- Parent PID (PPID): Process that started this process
- User: Who owns/runs the process
- State: Running, Sleeping, Stopped, Zombie
- Priority: How much CPU to allocate (nice value)
Daemons vs interactive processes:**
- Daemon: Runs in background, no terminal (Apache, MySQL, SSH)
- Interactive: Runs in foreground with terminal input (bash, vim, node)
View Running Processes
Simple process list:**
ps # Simple list of current shell's processes
ps aux # All processes, detailed (A=all, u=user-oriented, x=no-terminal)
ps axjf # Tree view showing parent-child relationships
ps output explained:**
USER PID %CPU %MEM VSZ RSS STAT START TIME COMMAND
root 1 0.0 0.1 19352 4032 Ss 12:00 0:01 /sbin/init
USER: Who owns the process
PID: Process ID
%CPU: CPU usage percentage
%MEM: Memory usage percentage
STAT: Status (S=sleeping, R=running, Z=zombie, T=stopped)
START: When process started
TIME: CPU time used
COMMAND: Process name and arguments
Monitor real-time:**
top # Interactive process monitor (press 'q' to exit)
htop # Better version of top (if installed)
Foreground and Background
Run command in background:**
# Start with &
./long-running-script.sh &
[1] 12345 # Job number [1], PID 12345
# View background jobs
jobs
# Bring job to foreground
fg %1 # Brings job number 1 to foreground
fg %12345 # Or use PID
Suspend and resume:**
# Press Ctrl+Z in terminal to suspend (SIGSTOP)
^Z
[1]+ Stopped vim file.txt
# Resume in background
bg %1
# Resume in foreground
fg %1
Process Signals
Signals tell processes to do things:**
| Signal | Number | Purpose | Command |
|---|---|---|---|
| SIGTERM | 15 | Graceful shutdown (process can ignore) | kill -15 PID |
| SIGKILL | 9 | Force kill (no escape, never blocked) | kill -9 PID |
| SIGSTOP | 19 | Pause (Ctrl+Z) | kill -19 PID |
| SIGCONT | 18 | Resume | kill -18 PID |
| SIGHUP | 1 | Reload config (for daemons) | kill -1 PID |
Kill a process:**
# Graceful stop (recommended first)
kill -15 12345
# Wait 5 seconds, then force kill if needed
sleep 5 && kill -9 12345
# Kill by name (all instances)
pkill -f "node app.js"
Process Priority
Nice values range -20 (highest priority) to +19 (lowest):**
# Start process with low priority (don't hog CPU)
nice -n 10 ./backup-script.sh
# Change priority of running process
renice -n 5 -p 12345 # Set to nice value 5
renice -n -5 -p 12345 # Set to nice value -5 (higher priority)
View nice values:**
ps aux --sort=-nice
# NI column shows nice value
Systemd Service Management
Start/stop/restart services:**
systemctl start apache2
systemctl stop apache2
systemctl restart apache2
systemctl reload apache2 # Reload config without full restart
# Auto-start on boot
systemctl enable apache2
systemctl disable apache2
# Check status
systemctl status apache2
systemctl is-active apache2
View systemd services:**
systemctl list-units --type=service
systemctl list-units --type=service --state=failed # Show failed services
Resource Limits
Limit process resource usage:**
# Limit to 500MB memory
ulimit -v 512000
# Limit CPU time to 1 hour
ulimit -t 3600
# Limit open files
ulimit -n 1024
# Run command with limits
systemd-run --scope -p MemoryLimit=500M /usr/bin/program
Systemd unit resource limits:**
# In /etc/systemd/system/myapp.service
[Service]
MemoryLimit=500M
CPUQuota=50%
TasksMax=100
Troubleshooting
Process not responding (zombie):**
- Show zombie processes:
ps aux | grep Z - Kill parent process:
kill -9 [PPID] - Reboot as last resort
Process consuming too much CPU/memory:**
- Identify:
ps aux --sort=-%cpu | head -5 - Check why:
ps auxww | grep PID(see full command line) - Kill if needed:
kill -9 PID - Investigate:
journalctl -u service-name(for systemd services)
Service won't start:**
# Check service status
systemctl status apache2
# View detailed errors
journalctl -u apache2 -n 50
# Test config manually
apache2ctl -t # For Apache
SIGTERM (kill -15) allows graceful shutdown. SIGKILL (kill -9) forces death. Use SIGTERM first; only use SIGKILL if SIGTERM fails.
Related: Systemd services | Bash scripting | Resource limits | Process monitoring
Need a developer-friendly server?
Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.





















