Pertemuan 5: Manajemen Proses

1. Pendahuluan

Setiap program yang berjalan dalam sistem operasi disebut sebagai proses. Memahami bagaimana mengelola proses adalah keterampilan fundamental bagi administrator sistem.

Importance: Kemampuan mengelola proses essential untuk memastikan kinerja sistem yang optimal, troubleshooting masalah, dan menjaga stabilitas sistem.
Performance
Optimal resource usage
Troubleshooting
Identify issues quickly
Security
Monitor suspicious activity
Stability
Maintain system reliability

2. Konsep Dasar Proses

Definisi Proses
  • Program yang sedang dieksekusi
  • Memiliki PID (Process ID) yang unik
  • Mengonsumsi resource (CPU, memory, I/O)
  • Memiliki environment dan konteks eksekusi
Process vs Program
Program
Kode biner di disk
/usr/bin/ls
Process
Instance di memory
PID: 1234
Jenis-jenis Proses:
Foreground Process

Berinteraksi dengan user

  • Memerlukan user input
  • Running di terminal
  • Contoh: text editor, web browser
$ vim file.txt # Foreground process
Background Process

Berjalan di belakang layar

  • Tidak perlu user interaction
  • Bisa di-control via job control
  • Contoh: compilation, data processing
$ gcc program.c & # Background process
Daemon Process

Proses sistem background

  • System services
  • No controlling terminal
  • Contoh: sshd, nginx, mysql
systemctl status sshd # Daemon process

3. Process States (Status Proses)

Linux Process States:
Status Kode Deskripsi Contoh
Running R Sedang dieksekusi CPU Active computation
Sleeping S Menunggu event atau resource Waiting for I/O
Stopped T Dihentikan sementara oleh signal Debugging pause
Zombie Z Proses telah selesai tapi entry masih ada Parent belum reap
Dead X Proses yang sepenuhnya terminated Fully cleaned up
Process Lifecycle:
Created
Ready
Running
Waiting
Terminated
Zombie Processes: Terjadi ketika child process selesai tetapi parent process belum membaca exit statusnya. Biasanya hilang setelah parent process mereap status.

4. Monitoring Processes di Linux

ps (Process Status)

Snapshot of current processes

Basic Usage:
# Semua proses dengan detail
ps aux

# Format lengkap
ps -ef

# Proses milik user tertentu
ps -u username

# Proses berdasarkan PID
ps -p 1234
Output Fields:
  • USER - Process owner
  • PID - Process ID
  • %CPU - CPU usage
  • %MEM - Memory usage
  • COMMAND - Command line
top & htop

Real-time process monitoring

Basic Usage:
# Basic real-time monitor
top

# Enhanced version dengan UI
htop
Important Shortcuts:
qQuit
kKill process
rRenice process
PSort by CPU
MSort by Memory
1Show all CPUs
pidof & pgrep

Process searching tools

Find Process by Name:
# Cari PID dari process name
pidof nginx

# Output: 1234 5678
Advanced Searching:
# Cari PID dengan pattern
pgrep -u root sshd

# Cari dengan full command match
pgrep -f "nginx: master process"
/proc Filesystem

Virtual filesystem untuk process info

Explore Process Info:
# List semua processes
ls /proc/

# Detail process tertentu
cat /proc/1234/status

# Memory info
cat /proc/meminfo

# System load
cat /proc/loadavg
Important Files:
  • /proc/PID/status
  • /proc/PID/cmdline
  • /proc/PID/environ
  • /proc/PID/fd/

5. Process Management di Linux

Mengirim Signal ke Proses:
Process Termination
# Force kill process
kill -9 1234

# Graceful termination
kill -15 1234

# Kill by process name
pkill nginx

# Kill all processes dengan nama
killall chrome
Process Control
# Pause process
kill -STOP 1234

# Resume paused process
kill -CONT 1234

# Interrupt process (Ctrl+C)
kill -INT 1234

# Hangup signal
kill -HUP 1234
Background Job Management:
Job Control
# Jalankan di background
./script.sh &

# Lihat background jobs
jobs

# Bawa job 1 ke foreground
fg %1

# Lanjutkan job 1 di background
bg %1
Process Priority
# Jalankan dengan priority 10
nice -n 10 ./script.sh

# Ubah priority proses berjalan
renice -n 5 -p 1234

# Check current nice value
ps -o pid,ni,comm -p 1234

Nice Range: -20 (highest priority) to 19 (lowest priority)

6. Monitoring Processes di Windows

Task Manager

GUI process monitoring

Quick Access:
  • Ctrl+Shift+Esc - Direct open
  • Ctrl+Alt+Delete - Security screen
Tabs:
  • Processes - Running applications
  • Performance - System resources
  • App history - Resource usage history
  • Startup - Startup programs
PowerShell
Process Commands:
# Semua processes
Get-Process

# Processes by name
Get-Process -Name "chrome"

# Stop process
Stop-Process -Name "notepad"
Stop-Process -ID 1234

# Performance monitoring
Get-Counter "\Process(*)\% Processor Time"
Command Prompt
Traditional Tools:
# List semua processes
tasklist

# Kill process by PID
taskkill /PID 1234

# Kill by image name
taskkill /IM notepad.exe /F

# Force kill
taskkill /F /IM chrome.exe
Resource Monitor

Detailed resource monitoring

Access:
resmon atau melalui Task Manager → Performance → Open Resource Monitor
Key Tabs:
  • Overview - System summary
  • CPU - Process CPU usage
  • Memory - Physical/virtual memory
  • Disk - Disk activity per process
  • Network - Network usage

7. Advanced Process Monitoring

System Performance Tools:
Linux Performance Tools
# Virtual memory statistics
vmstat 1 10

# I/O statistics
iostat -xz 1

# CPU activity sampling
sar -u 1 3

# Process tree view
pstree

# Process hierarchy
ps -ef --forest
Windows Performance Tools
# Performance Monitor
perfmon

# Command line performance
typeperf

# Process resource usage
Get-Counter "\Process(*)\% Processor Time"

# Memory usage
Get-Counter "\Memory\Available MBytes"
Liveness Monitoring:
Process Health Check
# Check if process is running
ps -p 1234 > /dev/null && echo "Running" || echo "Not running"

# Script untuk service monitoring
#!/bin/bash
if ! pgrep -x "nginx" > /dev/null; then
  echo "Nginx is down, restarting..."
  systemctl start nginx
fi
Process Investigation
# Cari proses yang lock file
lsof /var/lib/mysql/mysql.sock

# Cari proses menggunakan device
fuser -v /dev/sda1

# Check open files oleh process
ls -la /proc/1234/fd/

# Network connections by process
ss -tunlp | grep 1234

8. Troubleshooting Process Issues

High CPU Usage
Identification:
# Identifikasi proses CPU-intensive
ps aux --sort=-%cpu | head -10

# Monitor proses tertentu
top -p 1234

# Real-time CPU monitoring
htop
Common Causes:
  • Infinite loops
  • Poorly optimized code
  • Resource contention
  • Malware
High Memory Usage
Identification:
# Identifikasi proses memory-hog
ps aux --sort=-%mem | head -10

# Detail memory usage
cat /proc/1234/status | grep VmRSS

# Memory info
free -h
Common Causes:
  • Memory leaks
  • Large datasets
  • Inefficient algorithms
  • Cache buildup
Zombie Processes
Identification:
# Cari zombie processes
ps aux | grep defunct
ps aux | awk '$8=="Z" {print}'

# Check process state
ps -o pid,state,comm -p 1234
Solutions:
  • Kill parent process
  • Wait for parent to reap
  • Restart the service
  • System reboot (last resort)
Process Locks
Identification:
# Cari proses lock file
lsof /path/to/locked/file

# Cari proses menggunakan device
fuser -v /dev/sda1

# Check file locks
cat /proc/locks
Solutions:
  • Kill locking process
  • Force unmount
  • Restart service
  • Check for stale NFS locks

9. Best Practices Process Management

Monitoring Strategy
  • Regular health checks dengan scripting
  • Alerting untuk resource thresholds
  • Logging process crashes dan anomalies
  • Centralized monitoring system
Resource Management
  • Set appropriate process limits (ulimit)
  • Use cgroups (Control Groups) untuk resource containment
  • Implement proper service management (systemd, supervisord)
  • Monitor and tune kernel parameters
Security Considerations
  • Minimal privilege principle untuk service accounts
  • Regular audit processes dan services
  • Monitor suspicious process activity
  • Implement process whitelisting

10. Studi Kasus: Web Server Performance Issue

Scenario:

Web server tiba-tiba lambat, CPU usage 100%. Users complain about slow response times.

Troubleshooting Steps:
1. Identify High CPU Processes
# Cari proses CPU-intensive
ps aux --sort=-%cpu | head -10

# Output example:
# USER PID %CPU %MEM COMMAND
# www-data 1234 95.2 2.1 /usr/bin/php
2. Analyze Process Tree
# Lihat process hierarchy
pstree -p 1234

# atau
ps -ef --forest | grep 1234
3. Check Resource Usage
# Detail resource usage
cat /proc/1234/status

# Memory usage
cat /proc/1234/status | grep Vm

# Open files
lsof -p 1234 | wc -l
4. Take Action & Investigate
# Kill problematic process jika diperlukan
kill -TERM 1234

# Restart service
systemctl restart nginx

# Check application logs
tail -f /var/log/nginx/error.log
Root Cause Analysis:
  • Application bug - Infinite loop in PHP script
  • Configuration issue - Wrong PHP-FPM settings
  • Resource contention - Database connection issues
  • Malware - Cryptocurrency miner

11. Process Management Simulator

Interactive Process Simulator
Process Controls:
System Load:
CPU: 10%
Memory: 20%
Running Processes:
No processes running...
Process Management Commands:
# Process commands will appear here
# Try starting some processes!

Ringkasan Pembelajaran

Pada pertemuan ini kita telah mempelajari manajemen proses yang komprehensif, termasuk monitoring, kontrol, troubleshooting, dan best practices.

Key Takeaways:
  • Pemahaman process states dan lifecycle
  • Monitoring tools di Linux dan Windows
  • Process control dan signal management
  • Troubleshooting common process issues
Next Topic Preview:

Pertemuan berikutnya: Konfigurasi DNS dan DHCP - layanan jaringan fundamental untuk infrastruktur IT.