Tujuan Pembelajaran
Setelah menyelesaikan praktikum ini, mahasiswa mampu:
- Memahami konsep proses dan manajemen proses dalam sistem operasi
- Menggunakan perintah untuk memantau dan menganalisis proses yang berjalan
- Mengelola proses (start, stop, pause, resume) dengan perintah yang tepat
- Mengidentifikasi dan menangani proses yang bermasalah (zombie, runaway)
- Mengatur prioritas proses menggunakan nice dan renice
Teori Pendukung
Konsep Dasar Proses
Process ID (PID)
Nomor unik identifikasi proses
Parent PID (PPID)
PID proses pembuat
Owner
User yang menjalankan proses
Priority
Prioritas eksekusi CPU
Process States (Status Proses)
| Status |
Kode |
Deskripsi |
Contoh |
| Running |
R |
Proses sedang dieksekusi CPU |
Program aktif |
| Sleeping |
S |
Proses menunggu event |
Menunggu I/O |
| Stopped |
T |
Proses dihentikan sementara |
Debugging |
| Zombie |
Z |
Proses telah selesai tapi entry masih ada |
Process cleanup needed |
Jenis-jenis Sinyal (Signals)
| Sinyal |
Numeric |
Default Action |
Keterangan |
SIGTERM |
15 |
Terminate |
Permintaan terminasi yang graceful |
SIGKILL |
9 |
Terminate |
Paksa terminasi proses (tidak bisa di-handle) |
SIGSTOP |
19 |
Stop |
Menjeda proses |
SIGCONT |
18 |
Continue |
Melanjutkan proses yang dihentikan |
SIGHUP |
1 |
Terminate |
Hang up (reload configuration) |
SIGINT |
2 |
Terminate |
Interrupt dari keyboard (Ctrl+C) |
Jenis Proses
- Dijalankan oleh user biasa
- PID biasanya > 1000
- Contoh: browser, text editor
- Berjalan di foreground/background
- Proses sistem yang berjalan di background
- PID biasanya < 1000
- Contoh: sshd, nginx, mysql
- Dimulai saat boot
Monitoring Processes
1. ps - Process Status
ps [options]
ps
ps aux
ps -ef
ps -u username
ps -p PID
ps aux --sort=-%cpu | head -10
ps aux --sort=-%mem | head -10
ps aux | grep nginx
2. top - Real-time Process Monitoring
top [options]
q
k
r
M
P
1
top -bn1
3. htop - Enhanced Process Viewer
sudo apt install htop
sudo yum install htop
htop [options]
Mouse support
Tree view
Color-coded
Search
htop -u username
htop -p PID1,PID2
4. pidof & pgrep - Find Process ID
pidof process_name
pgrep process_name
pidof nginx
pgrep -u root
pgrep -f "pattern"
Process Management
1. kill - Mengirim Sinyal ke Proses
kill [options] PID
kill -s SIGNAL PID
kill -SIGNAL PID
kill 1234
kill -9 1234
kill -TERM 1234
kill -HUP 1234
2. pkill & killall - Kill by Name
pkill [options] pattern
killall [options] process_name
pkill nginx
pkill -9 chrome
pkill -u username
killall firefox
killall -v process_name
3. nice & renice - Process Priority
Nice Value Range: -20 (highest priority) to 19 (lowest priority)
nice -n priority command
renice priority -p PID
nice -n -10 ./cpu_intensive_script.sh
nice -n 10 ./background_task.sh
renice -5 1234
renice 15 -u username
4. nohup - Run Process After Logout
nohup command &
nohup ./long_running_script.sh > output.log 2>&1 &
nohup python3 server.py > server.log 2>&1 &
Langkah-langkah Praktikum
A. Persiapan Environment dan Proses Contoh
sudo -i
sleep 300 &
ping -c 100 localhost > /dev/null &
tail -f /var/log/syslog > /dev/null &
cat > /tmp/cpu_test.sh << 'EOF'
#!/bin/bash
while true; do
echo "CPU test process running..." > /dev/null
done
EOF
chmod +x /tmp/cpu_test.sh
/tmp/cpu_test.sh &
B. Monitoring Processes dengan ps
ps
ps aux
ps aux --sort=-%cpu | head -10
ps aux --sort=-%mem | head -10
ps aux | grep sleep
ps aux | grep ping
ps aux | grep cpu_test
C. Real-time Monitoring dengan top dan htop
top
sudo apt install htop -y
sudo yum install htop -y
htop
htop -p $(pgrep sleep | tr '\n' ',' | sed 's/,$//')
D. Mengelola Proses dengan kill, pkill, killall
ps aux | grep sleep
PID_SLEEP=$(pgrep sleep | head -1)
echo "PID sleep: $PID_SLEEP"
kill $PID_SLEEP
sleep 600 &
PID_SLEEP=$(pgrep sleep | head -1)
kill -9 $PID_SLEEP
ping -c 1000 localhost > /dev/null &
pkill ping
sleep 300 &
sleep 400 &
killall sleep
E. Mengatur Prioritas Proses dengan nice dan renice
nice -n -10 /tmp/cpu_test.sh &
PID_HIGH_PRIORITY=$!
nice -n 10 /tmp/cpu_test.sh &
PID_LOW_PRIORITY=$!
ps -l -p $PID_HIGH_PRIORITY
ps -l -p $PID_LOW_PRIORITY
renice -5 $PID_LOW_PRIORITY
renice 15 $PID_HIGH_PRIORITY
ps -l -p $PID_HIGH_PRIORITY,$PID_LOW_PRIORITY
F. Menangani Proses Zombie dan Troubleshooting
ps aux | grep defunct
ps aux | awk '$8=="Z" {print $2}'
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10
pstree
pstree -p
sudo apt install iotop -y
iotop
G. Advanced Process Management
nohup /tmp/cpu_test.sh > /tmp/cpu_test.log 2>&1 &
sudo apt install screen -y
screen -S long_running_process
/tmp/cpu_test.sh
cat > /etc/systemd/system/test-service.service << 'EOF'
[Unit]
Description=Test Service for Practicum
After=network.target
[Service]
Type=simple
ExecStart=/tmp/cpu_test.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start test-service
systemctl status test-service
Advanced Process Monitoring
1. Process Tree dengan pstree
pstree
pstree -p
pstree -u
pstree -a
pstree -A
2. Detailed Process Information
cat /proc/$PID/environ | tr '\0' '\n'
pmap $PID
lsof -p $PID
cat /proc/$PID/limits
3. strace & ltrace - Process Tracing
strace command
strace -p $PID
strace -c command
ltrace command
ltrace -p $PID
4. System Resource Monitoring
free -h
cat /proc/meminfo
mpstat
cat /proc/loadavg
iostat
vmstat
Tugas dan Evaluasi
- Apa perbedaan antara proses zombie dan orphan process?
- Kapan sebaiknya menggunakan SIGTERM dan kapan menggunakan SIGKILL?
- Jelaskan apa yang terjadi ketika kita mengubah nice value suatu proses!
- Bagaimana cara mengidentifikasi proses yang menggunakan resource CPU berlebihan?
- Buat skenario: Sebuah proses menjadi tidak responsif dan menggunakan 100% CPU. Tulis langkah-langkah troubleshooting yang sistematis!
Troubleshooting Script
Performance Troubleshooting Script
cat > /usr/local/bin/performance_check.sh << 'EOF'
#!/bin/bash
# Script untuk identifikasi penyebab server lambat
echo "=== SYSTEM STATUS ==="
uptime
echo ""
echo "=== TOP 5 CPU PROCESSES ==="
ps aux --sort=-%cpu | head -6
echo ""
echo "=== TOP 5 MEMORY PROCESSES ==="
ps aux --sort=-%mem | head -6
echo ""
echo "=== ZOMBIE PROCESSES ==="
ps aux | grep defunct
echo ""
echo "=== I/O STATISTICS ==="
iostat -x 1 1
EOF
chmod +x /usr/local/bin/performance_check.sh
Process Monitoring Dashboard
cat > /usr/local/bin/process_monitor.sh << 'EOF'
#!/bin/bash
# Real-time process monitoring dashboard
while true; do
clear
echo "=== PROCESS MONITOR $(date) ==="
echo "Load Average: $(cat /proc/loadavg | awk '{print $1,$2,$3}')"
echo ""
echo "--- Top CPU Processes ---"
ps aux --sort=-%cpu | head -10
echo ""
echo "--- Top Memory Processes ---"
ps aux --sort=-%mem | head -10
sleep 5
done
EOF
Best Practices Process Management
- Monitor system load average secara berkala
- Gunakan SIGTERM sebelum SIGKILL
- Set appropriate nice values untuk background tasks
- Gunakan nohup/screen untuk long-running processes
- Monitor zombie processes dan clean up jika perlu
- Document process dependencies
- Jangan kill process tanpa memahami dependencies
- Jangan set nice value -20 untuk user processes
- Jangan biarkan zombie processes menumpuk
- Jangan ignore high load average warnings
- Jangan run critical processes tanpa monitoring
- Jangan gunakan SIGKILL sebagai first option
Load Average Interpretation
| Load Average |
Interpretasi |
Tindakan |
| < CPU cores |
System normal |
No action needed |
| ≈ CPU cores |
System busy |
Monitor closely |
| > CPU cores |
System overloaded |
Investigate immediately |
| >> CPU cores |
System severely overloaded |
Emergency action required |