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 processes

Process 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 session

Background 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 usage

CPU 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 users

Process 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 unit

Namespaces

# Namespace operations
unshare             # Create namespace
nsenter             # Enter namespace
lsns                # List namespaces
ip netns            # Network namespaces

๐Ÿ’ก Best Practices

  1. Process Management

    • Use appropriate signals

    • Monitor resource usage

    • Set proper priorities

    • Handle zombie processes

  2. Resource Control

    • Implement resource limits

    • Use cgroups effectively

    • Monitor system load

    • Plan capacity

  3. Monitoring

    • Regular process checks

    • Resource usage tracking

    • Performance monitoring

    • Log analysis

  4. 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 length

Performance Analysis

# Performance tools
perf                 # Performance analysis
sysdig              # System analysis
fatrace             # File access trace
pidstat             # Process statistics

๐Ÿ“š Process Documentation

  1. System Information

    • Process hierarchy

    • Resource limits

    • System capabilities

    • Performance baselines

  2. Monitoring Plan

    • Critical processes

    • Resource thresholds

    • Alert conditions

    • Response procedures

  3. Recovery Procedures

    • Process restart

    • Resource recovery

    • System restoration

    • Incident documentation

๐ŸŽ“ Learning Resources

  1. Process Concepts

    • Process states

    • Scheduling

    • Memory management

    • I/O management

  2. Tools and Utilities

    • Monitoring tools

    • Debug tools

    • Performance tools

    • Analysis tools

  3. Best Practices

    • Resource management

    • Performance tuning

    • Security measures

    • Monitoring strategies

Last updated

Was this helpful?