Linux Process Management Cheat Sheet
Überblick
Linux Prozessmanagement beinhaltet die Überwachung, Steuerung und Optimierung von laufenden Prozessen und Systemressourcen. Dieser umfassende Leitfaden umfasst Prozessüberwachungstools, Signalhandling, Jobsteuerung, Systemressourcenmanagement und Leistungsoptimierungstechniken, die für Systemadministratoren und IT-Profis unerlässlich sind.
ZEIT Warning: Prozessabbruchbefehle wie
kill -9
können Datenverlust verursachen. Versuchen Sie immer anmutige Kündigung zuerst und stellen Sie richtige Backups.
Prozessansicht und Überwachung
Grundlegende Prozessinformationen
```bash
Display running processes
ps ps aux # All processes with detailed info ps -ef # Full format listing ps -u username # Processes for specific user ps -p PID # Specific process by PID
Process tree view
pstree pstree -p # Show PIDs pstree username # Processes for specific user
Real-time process monitoring
top htop # Enhanced interactive process viewer ```_
Erweiterte Prozessüberwachung
```bash
Detailed process information
ps auxf # Process tree format ps -eo pid,ppid,cmd,pcpu,pmem # Custom columns
Process by resource usage
ps aux --sort=-pcpu # Sort by CPU usage ps aux --sort=-pmem # Sort by memory usage
Long-running processes
ps -eo pid,etime,cmd # Show elapsed time
Zombie processes
ps aux|grep -w Z ps -eo stat,pid,cmd|grep -w Z ```_
Echtzeit-Systemüberwachung
```bash
Interactive process monitor
top
Top commands:
k - kill process
r - renice process
M - sort by memory
P - sort by CPU
q - quit
Enhanced process monitor
htop
htop features:
F9 - kill process
F7/F8 - nice/renice
F6 - sort options
F10 - quit
System activity reporter
sar -u 1 10 # CPU usage every 1 second, 10 times sar -r 1 10 # Memory usage sar -d 1 10 # Disk activity ```_
Prozesssteuerung und Signale
Signaltypen
```bash
Common signals:
SIGTERM (15) - Graceful termination
SIGKILL (9) - Force kill (cannot be caught)
SIGHUP (1) - Hangup (reload config)
SIGSTOP (19) - Stop process
SIGCONT (18) - Continue stopped process
SIGINT (2) - Interrupt (Ctrl+C)
```_
Killing Processes
```bash
Kill by PID
kill PID kill -15 PID # Send SIGTERM (default) kill -9 PID # Force kill with SIGKILL kill -HUP PID # Send hangup signal
Kill by process name
killall process_name killall -9 process_name
Kill by pattern
pkill pattern pkill -f pattern # Match full command line pkill -u username # Kill user's processes
Interactive process killer
top # Press 'k' then enter PID htop # Press F9 then select process ```_
Prozesspriorität und Nizza Werte
```bash
View process priorities
ps -eo pid,ni,cmd
Start process with specific priority
nice -n 10 command # Lower priority (+10) nice -n -5 command # Higher priority (-5)
Change running process priority
renice 10 PID # Set nice value to 10 renice -5 -p PID # Set nice value to -5 renice 5 -u username # Renice all user processes ```_
Job Control
Hintergrund und Vordergrund Jobs
```bash
Run command in background
command &
List active jobs
jobs jobs -l # Show PIDs
Bring job to foreground
fg fg %1 # Bring job 1 to foreground
Send job to background
bg bg %1 # Send job 1 to background
Suspend current job
Ctrl+Z
Resume suspended job
fg # Resume in foreground bg # Resume in background ```_
Dauerhafte Prozesse
```bash
Run command immune to hangups
nohup command & nohup command > output.log 2>&1 &
Detach from terminal
disown %1 # Disown job 1 disown -a # Disown all jobs
Screen sessions
screen # Start new session screen -S name # Named session screen -r # Reattach to session screen -ls # List sessions
Tmux sessions
tmux # Start new session tmux new -s name # Named session tmux attach -t name # Attach to session tmux list-sessions # List sessions ```_
Systemressourcenüberwachung
CPU Überwachung
```bash
CPU usage overview
top htop vmstat 1 # Virtual memory statistics iostat 1 # I/O and CPU statistics
Per-CPU statistics
mpstat # Multi-processor statistics mpstat -P ALL 1 # All CPUs every second
CPU load averages
uptime w # Who is logged in and load cat /proc/loadavg # Load average file ```_
Speicherüberwachung
```bash
Memory usage
free free -h # Human readable free -m # In megabytes free -s 1 # Update every second
Detailed memory information
cat /proc/meminfo vmstat 1 # Virtual memory stats
Memory usage by process
ps aux --sort=-pmem|head -10 top -o %MEM # Sort by memory in top
Memory map of process
pmap PID pmap -d PID # Detailed mapping ```_
Disk I/O Monitoring
```bash
Disk usage
df -h # Filesystem usage du -sh /path # Directory usage
I/O statistics
iostat iostat -x 1 # Extended stats every second iotop # Real-time I/O monitoring
Disk activity by process
iotop -o # Only show active processes pidstat -d 1 # Per-process I/O stats ```_
Netzwerküberwachung
```bash
Network connections
netstat -tuln # TCP/UDP listening ports ss -tuln # Modern replacement for netstat ss -p # Show process names
Network activity
netstat -i # Interface statistics iftop # Real-time network usage nethogs # Network usage by process
Network connections by process
lsof -i # Network files lsof -i :80 # Processes using port 80 ```_
Prozessanalyse und Debugging
Informationen zum Thema
```bash
Detailed process info
cat /proc/PID/status cat /proc/PID/cmdline cat /proc/PID/environ
Process file descriptors
lsof -p PID ls -la /proc/PID/fd/
Process memory maps
cat /proc/PID/maps pmap PID
Process threads
ps -T -p PID top -H -p PID ```_
Systemanrufe und Debugging
```bash
Trace system calls
strace command strace -p PID # Attach to running process strace -f command # Follow forks
Library calls
ltrace command ltrace -p PID
Debug running process
gdb -p PID ```_
Leistungsanalyse
```bash
Process CPU usage over time
pidstat 1 # Per-process statistics pidstat -p PID 1 # Specific process
Memory usage tracking
pidstat -r 1 # Memory statistics pidstat -d 1 # Disk I/O statistics
System performance overview
vmstat 1 10 # Virtual memory stats sar -A # All system activity ```_
Systemdienstleistungen und Daemons
Systemisches Servicemanagement
```bash
Service status
systemctl status service_name systemctl is-active service_name systemctl is-enabled service_name
Start/stop services
systemctl start service_name systemctl stop service_name systemctl restart service_name systemctl reload service_name
Enable/disable services
systemctl enable service_name systemctl disable service_name
List services
systemctl list-units --type=service systemctl list-units --failed ```_
Service Logs
```bash
View service logs
journalctl -u service_name journalctl -u service_name -f # Follow logs journalctl -u service_name --since today
System logs
journalctl journalctl -f # Follow system logs journalctl --since "1 hour ago" journalctl -p err # Error messages only ```_
Prozessautomatisierung und -planung
Cron Jobs
```bash
Edit crontab
crontab -e crontab -l # List cron jobs crontab -r # Remove all cron jobs
System cron directories
ls /etc/cron.d/ ls /etc/cron.daily/ ls /etc/cron.hourly/ ls /etc/cron.weekly/ ls /etc/cron.monthly/
Cron log
tail -f /var/log/cron ```_
Bei Jobs (Einmalige Planung)
```bash
Schedule one-time job
at 15:30 at now + 1 hour at tomorrow
List scheduled jobs
atq at -l
Remove scheduled job
atrm job_number ```_
Probleme bei der Fehlerbehebung
Hohe CPU Verwendung
```bash
Find CPU-intensive processes
top -o %CPU ps aux --sort=-pcpu|head -10
CPU usage by command
pidstat -u 1
System load investigation
uptime vmstat 1 sar -u 1 10 ```_
Hohe Speichernutzung
```bash
Memory-intensive processes
ps aux --sort=-pmem|head -10 top -o %MEM
Memory leaks detection
valgrind --leak-check=full command
Out of memory investigation
dmesg|grep -i "killed process" grep -i "out of memory" /var/log/messages ```_
Zombie Prozesse
```bash
Find zombie processes
ps aux|awk '$8 ~ /^Z/ \\{ print $2 \\}' ps -eo stat,pid,cmd|grep -w Z
Kill parent of zombie
ps -o ppid= -p zombie_pid kill parent_pid ```_
Prozess nicht reagieren
```bash
Check if process is hung
kill -0 PID # Test if process exists strace -p PID # See what process is doing
Force termination
kill -TERM PID # Try graceful first sleep 5 kill -KILL PID # Force if necessary ```_
Leistungsoptimierung
Prozessbeschränkungen
```bash
View current limits
ulimit -a cat /proc/PID/limits
Set limits
ulimit -n 4096 # File descriptors ulimit -u 1024 # Max user processes ulimit -m 1048576 # Memory limit (KB)
System-wide limits
cat /etc/security/limits.conf ```_
CPU Affinität
```bash
View CPU affinity
taskset -p PID
Set CPU affinity
taskset -p 0x1 PID # CPU 0 only taskset -p 0x3 PID # CPU 0 and 1 taskset -c 0,1 PID # CPU 0 and 1
Start process with affinity
taskset -c 0 command ```_
Ressourcen
- [Linux Process Management Guide](__LINK_4___ -%20Systemd%20Dokumentation
- (__LINK_4___)
- (__LINK_4___)
--
*Dieses Cheatsheet bietet umfassende Prozessmanagement-Befehle für Linux-Systeme. Verstehen Sie immer die Auswirkungen von Prozesssteuerungsbefehlen, bevor Sie sie in Produktionsumgebungen verwenden. *