월. 8월 4th, 2025

Introduction to Linux Processes
Every program running on your Linux system is a process – an instance of executing code managed by the kernel. Understanding process management is crucial for system administration, troubleshooting, and resource optimization. Each process has a unique PID (Process ID) and runs within its own isolated environment.

Viewing Active Processes

  • ps aux: Snapshots all running processes (user, PID, CPU/memory usage, command)
  • top: Interactive real-time process viewer (press q to exit)
  • htop (install via sudo apt install htop): Enhanced color-coded view with mouse support
  • pstree -p: Displays processes in hierarchical tree format showing parent-child relationships

Managing Process States

  • Start a process: Simply type the command (e.g., firefox)
  • Background execution: Append & (e.g., long_running_task &)
  • Suspend a process: Press Ctrl+Z
  • Resume in background: bg %jobnumber (check jobs with jobs)
  • Bring to foreground: fg %jobnumber
  • Detach from terminal: Use nohup (e.g., nohup ./script.sh &)

Process Priority Control
Linux uses niceness values (-20 highest priority to 19 lowest):

  • Launch with priority: nice -n 10 cpu_intensive_task
  • Change running process priority: sudo renice -n 5 -p 1234

Terminating Processes

  • Graceful termination: kill -15 PID (SIGTERM)
  • Force kill: kill -9 PID (SIGKILL)
  • Kill by name: killall firefox
  • Interactive kill: top → press k → enter PID

Advanced Monitoring Tools

  • vmstat 2: System-wide resource stats every 2 seconds
  • lsof -p PID: List files opened by a process
  • pidof sshd: Find PIDs of specific processes
  • /proc/PID/: Directory containing real-time process details

Systemd Service Management
For modern distributions:

  • Start service: sudo systemctl start nginx
  • Enable auto-start: sudo systemctl enable nginx
  • Check status: systemctl status nginx
  • View logs: journalctl -u nginx -f

Pro Tips for Power Users

  1. Use screen or tmux for persistent terminal sessions
  2. Limit process resources with ulimit or cgroups
  3. Identify resource hogs: top → sort by CPU (P) or Memory (M)
  4. Kill zombie processes by terminating their parent
  5. Set CPU affinity with taskset

Conclusion
Effective process management separates Linux novices from experts. By mastering these commands, you gain precise control over system resources, improve stability, and troubleshoot like a pro. Remember: always prefer SIGTERM (15) over SIGKILL (9) to allow graceful shutdowns. Practice these techniques in a safe environment to build confidence!

> Note: Replace PID with actual process IDs and customize commands for your distribution’s package manager (apt/dnf/yum). Always verify processes before termination!

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다