토. 8월 2nd, 2025

Introduction

Every running application on Linux is a process – an instance of a program consuming resources. Sometimes processes misbehave (freeze, hog CPU/memory) or need intentional termination. This guide explores ps (process status) and kill – essential tools for process management.


1️⃣ Listing Processes with ps

Basic Syntax:

ps [options]

Key Options:

Option Description Example
aux Show all user-owned processes ps aux
-ef Display full-format process list ps -ef
-u Filter by user ps -u ubuntu
--sort Sort output (e.g., -pcpu, -pmem) ps aux --sort=-pcpu

Output Explained:

USER  PID %CPU %MEM VSZ    RSS   TTY  STAT START TIME COMMAND  
root  123 0.5  1.2  102344 6784 ?    S    Jan01 1:23 /usr/sbin/nginx
  • PID: Unique Process ID (critical for kill)
  • %CPU/%MEM: Resource usage
  • COMMAND: Process name/path
  • STAT: Process state (e.g., S=sleeping, R=running, Z=zombie)

Finding Processes:

ps aux | grep "chrome"  # Find Chrome processes

2️⃣ Terminating Processes with kill

Basic Syntax:

kill [signal] [PID]

Common Signals:

Signal Number Purpose
SIGTERM 15 Polite termination (default). Allows cleanup.
SIGKILL 9 Force kill. Immediate, no cleanup. Use as last resort!
SIGHUP 1 Reload configuration (e.g., daemons).

Examples:

kill 1234          # Send SIGTERM to PID 1234  
kill -9 1234       # Force-kill PID 1234  
kill -SIGHUP 789   # Reload process 789

Killing by Process Name:

Use pkill or killall:

pkill firefox        # Terminate all Firefox instances  
killall -9 chromium  # Force-kill all Chromium processes

3️⃣ Step-by-Step Workflow

  1. Identify misbehaving processes:
    ps aux --sort=-%cpu | head -n 5  # Top 5 CPU hogs
  2. Terminate gracefully first:
    kill 5678  # SIGTERM
  3. Force-kill if unresponsive:
    kill -9 5678  # SIGKILL
  4. Verify termination:
    ps -p 5678  # Check if PID 5678 still exists

⚠️ Critical Warnings

  • Never kill -9 system processes (may crash OS).
  • Avoid killing processes you don’t understand – research first!
  • SIGKILL (-9) is destructive:
    • No resource cleanup (memory leaks possible).
    • Unsaved data in apps (e.g., editors) will be lost.

💡 Pro Tips

  • Use htop (interactive process viewer) for easier navigation.
  • Daemons/services: Prefer service managers (systemctl restart nginx).
  • Zombie processes: Often need parent process killed first.

Conclusion

ps and kill are fundamental for Linux process control:

  1. psInspect resource usage and identify PIDs.
  2. killTerminate safely (SIGTERM) or forcefully (SIGKILL).
    Always default to polite termination first! With great power comes great responsibility – wield these tools wisely 🔧🐧.

답글 남기기

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