Process Management
A comprehensive guide to Linux process management, monitoring, and control.
๐ Process Basics
Process Information
# Basic process commands
ps # Show current processes
ps aux # Show all processes
ps -ef # Full process listing
pstree # Process tree view
top # Interactive process viewer
htop # Enhanced process viewer
# Process details
ps -p PID -f # Show specific process
ps --forest # Show process hierarchy
pidof process_name # Find process ID
pgrep pattern # Search processesProcess States
# Process states
R # Running
S # Sleeping (interruptible)
D # Uninterruptible sleep
Z # Zombie
T # Stopped
I # Idle kernel thread
# State monitoring
ps -eo pid,state,cmd # Show process states
watch -n 1 'ps -eo pid,state,cmd' # Monitor states๐ฎ Process Control
Process Management
# Process control
kill PID # Terminate process
killall process_name # Kill by name
pkill pattern # Kill by pattern
xkill # Kill GUI application
# Process signals
kill -l # List signals
kill -9 PID # Force kill (SIGKILL)
kill -15 PID # Graceful stop (SIGTERM)
kill -19 PID # Suspend (SIGSTOP)
kill -18 PID # Resume (SIGCONT)Process Priority
# Priority management
nice -n 10 command # Start with nice value
renice -n 10 -p PID # Change priority
chrt -p PID # Show scheduling
chrt -f -p 50 PID # Set real-time priority
# CPU affinity
taskset -p PID # Show CPU affinity
taskset -cp 0-2 PID # Set CPU affinity๐ Process Creation
Process Launching
# Process execution
./script.sh # Execute script
exec command # Replace current process
nohup command & # Run immune to hangups
screen command # Run in screen session
tmux command # Run in tmux sessionBackground Jobs
# Job control
command & # Run in background
bg # Send to background
fg # Bring to foreground
jobs # List jobs
disown # Detach job๐ Resource Management
Memory Management
# Memory usage
free -h # System memory
vmstat # Virtual memory stats
pmap PID # Process memory map
smem # Sorted memory usage
# Memory control
ulimit -v # Set virtual memory limit
cgroups # Control groups
systemd-cgtop # Show cgroup usageCPU Management
# CPU monitoring
mpstat # CPU statistics
sar # System activity
uptime # Load average
stress # CPU stress test
# CPU control
cpulimit -p PID # Limit CPU usage
nice # CPU priority
ionice # I/O priority๐ Process Monitoring
System Monitoring
# System tools
atop # Advanced system monitor
glances # System monitoring
nmon # Performance monitor
dstat # System statistics
# Resource monitoring
iotop # I/O monitoring
nethogs # Network monitoring
lsof # Open files
fuser # File usersProcess Debugging
# Debug tools
strace # System call tracer
ltrace # Library call tracer
gdb # GNU debugger
valgrind # Memory debugger
# Core dumps
ulimit -c # Core dump size
gcore PID # Generate core dump
coredumpctl # Manage core dumps๐ ๏ธ Advanced Features
Control Groups
# cgroup management
cgcreate # Create cgroup
cgexec # Execute in cgroup
cgset # Set cgroup parameters
cgdelete # Delete cgroup
# Resource limits
systemctl set-property # Set unit properties
systemd-run # Run in unitNamespaces
# Namespace operations
unshare # Create namespace
nsenter # Enter namespace
lsns # List namespaces
ip netns # Network namespaces๐ก Best Practices
Process Management
Use appropriate signals
Monitor resource usage
Set proper priorities
Handle zombie processes
Resource Control
Implement resource limits
Use cgroups effectively
Monitor system load
Plan capacity
Monitoring
Regular process checks
Resource usage tracking
Performance monitoring
Log analysis
Security
Process isolation
Resource restrictions
Access control
Audit logging
๐ง Troubleshooting
Common Issues
# Process issues
ps aux | grep defunct # Find zombies
ps aux --sort=-%mem # High memory usage
ps aux --sort=-%cpu # High CPU usage
dmesg | grep -i kill # OOM killer logs
# System issues
uptime # Load problems
vmstat 1 # Resource bottlenecks
iostat -x 1 # I/O problems
sar -q 1 # Queue lengthPerformance Analysis
# Performance tools
perf # Performance analysis
sysdig # System analysis
fatrace # File access trace
pidstat # Process statistics๐ Process Documentation
System Information
Process hierarchy
Resource limits
System capabilities
Performance baselines
Monitoring Plan
Critical processes
Resource thresholds
Alert conditions
Response procedures
Recovery Procedures
Process restart
Resource recovery
System restoration
Incident documentation
๐ Learning Resources
Process Concepts
Process states
Scheduling
Memory management
I/O management
Tools and Utilities
Monitoring tools
Debug tools
Performance tools
Analysis tools
Best Practices
Resource management
Performance tuning
Security measures
Monitoring strategies
Last updated
Was this helpful?