Jobs

A comprehensive guide to monitoring system resources, managing processes, and handling jobs in Linux.

πŸ“Š System Resource Monitoring

System Overview

# System information
uname -a                    # System and kernel information
hostnamectl                 # System and OS information
lsb_release -a             # Distribution information
uptime                     # System uptime and load

# Resource usage overview
top                        # Interactive process viewer
htop                       # Enhanced interactive process viewer
glances                    # Advanced system monitor

Memory Monitoring

# Memory usage
free -h                    # Memory usage in human-readable format
vmstat                     # Virtual memory statistics
cat /proc/meminfo          # Detailed memory information
swapon --show             # Show swap usage
smem                      # Memory usage per process

# Memory management
sync                      # Flush file system buffers
echo 3 > /proc/sys/vm/drop_caches  # Clear cache
swapoff -a && swapon -a   # Reset swap

CPU Monitoring

# CPU information
lscpu                     # CPU architecture information
cat /proc/cpuinfo         # Detailed CPU information
mpstat                    # CPU statistics
sar -u                    # CPU utilization report
stress-ng                 # CPU stress testing

# Load average
w                         # Show system load
uptime                    # Quick load average view
cat /proc/loadavg         # Raw load average data

Disk Monitoring

# Disk usage
df -h                     # Disk space usage
du -sh /*                 # Directory sizes
iostat                    # I/O statistics
iotop                     # I/O monitoring per process
fio                      # I/O performance testing

# Disk health
smartctl -a /dev/sda      # SMART disk information
hdparm -tT /dev/sda       # Disk read speed test
badblocks -v /dev/sda     # Check for bad sectors

πŸ”„ Process Management

Process Information

# Process listing
ps aux                    # List all processes
ps -ef                    # Full process listing
pstree                    # Process tree view
pidof process_name        # Find process ID

# Process details
ps -p PID -f             # Detailed process info
cat /proc/PID/status     # Process status
strace -p PID            # Trace process system calls
lsof -p PID              # List open files by process

Process Control

# Process manipulation
kill PID                  # Terminate process
killall process_name      # Kill by process name
pkill pattern            # Kill by pattern
renice -n 10 -p PID      # Change process priority
nice -n 10 command       # Start with priority

# Process signals
kill -l                  # List all signals
kill -9 PID              # Force kill (SIGKILL)
kill -15 PID             # Graceful termination (SIGTERM)
kill -19 PID             # Suspend process (SIGSTOP)

πŸ‘₯ Job Control

Job Management

# Job control
jobs                     # List background jobs
bg %job_number          # Send job to background
fg %job_number          # Bring job to foreground
ctrl+z                  # Suspend current job
command &               # Start job in background

# Job scheduling
at now + 1 hour         # Schedule one-time job
batch                   # Run job when system load permits
atq                     # List pending jobs
atrm job_number         # Remove scheduled job

Cron Jobs

# Cron management
crontab -l              # List cron jobs
crontab -e              # Edit cron jobs
crontab -r              # Remove all cron jobs

# Cron examples
# MIN HOUR DOM MON DOW CMD
0 * * * * command       # Run hourly
0 0 * * * command       # Run daily at midnight
0 0 * * 0 command       # Run weekly

πŸ“ˆ Performance Analysis

System Performance

# Performance tools
sysstat                 # System performance tools
sar                     # System activity reporter
perf                    # Performance analysis tools
strace                  # System call tracer

# Performance monitoring
vmstat 1               # Virtual memory stats every second
iostat -xz 1          # I/O stats every second
mpstat -P ALL 1       # CPU stats every second

Network Performance

# Network monitoring
netstat -tuln          # Active connections
ss -tuln              # Socket statistics
iftop                 # Network bandwidth monitor
nethogs               # Per-process network traffic

# Network testing
iperf3                # Network bandwidth testing
mtr hostname         # Network path analysis
tcpdump              # Network packet analysis

πŸ” Log Monitoring

System Logs

# Log viewing
journalctl           # View systemd logs
tail -f /var/log/syslog  # Follow system log
grep -i error /var/log/* # Search errors in logs
dmesg               # Kernel ring buffer

# Log analysis
logwatch            # Log analysis and reporting
fail2ban-client status  # Intrusion prevention status
last                # Login history
who                 # Current logins

πŸ› οΈ Advanced Monitoring

Resource Limits

# System limits
ulimit -a           # Show all limits
/etc/security/limits.conf  # Configure limits
sysctl -a          # Kernel parameters
nice              # Run with modified priority

Container Monitoring

# Docker monitoring
docker stats       # Container resource usage
docker top         # Container processes
docker logs        # Container logs
ctop              # Container monitoring tool

πŸ’‘ Best Practices

  1. Regular Monitoring

    • Set up automated monitoring

    • Define resource thresholds

    • Configure alerts

    • Keep monitoring history

  2. Resource Management

    • Monitor resource trends

    • Plan capacity

    • Set resource limits

    • Optimize usage

  3. Process Control

    • Use appropriate signals

    • Monitor critical processes

    • Set process priorities

    • Handle zombie processes

  4. Job Scheduling

    • Document scheduled jobs

    • Monitor job completion

    • Handle job failures

    • Manage job priorities

πŸ”§ Troubleshooting

Common Issues

# High CPU usage
top -c                # Identify CPU-intensive processes
ps aux --sort=-%cpu   # Sort by CPU usage
perf top             # CPU performance analysis

# Memory issues
free -h              # Check memory usage
ps aux --sort=-%mem  # Sort by memory usage
dmesg | grep -i oom  # Check OOM killer

Performance Issues

# System performance
sar -q               # Load average analysis
sar -r               # Memory utilization
sar -b               # I/O statistics
sar -n DEV          # Network statistics

# Process issues
strace -p PID        # Debug process
ltrace -p PID        # Library call tracer
lsof                # List open files
fuser               # Identify process using files

Last updated

Was this helpful?