Buffl

Viewing and Terminating Processes

as
von abdullah S.

Detailed Explanations


1. The ps Command (Process Status)

What it does: Displays a snapshot of currently running processes.

Default behavior: Shows only processes owned by the current user and associated with the current terminal.

Key Options:

  • ps (no options): Shows basic info about your processes

    • PID (Process ID): Unique number identifying each process

    • TTY (Terminal): Which terminal the process is associated with

    • TIME: CPU time used by the process

    • CMD: Command that started the process

  • ps -f (full format): Adds more columns:

    • UID: User ID who owns the process

    • PPID: Parent Process ID (which process started this one)

    • C: CPU utilization percentage

    • STIME: Start time when process began

  • ps -e: Shows ALL processes on the system (all users)

  • ps -ef: Combines both - shows all processes with full details

  • ps -u username: Shows processes for a specific user

Important Concepts:

  • Process ID (PID): Every process gets a unique number

  • Parent Process ID (PPID): Shows which process created this one

  • PID 1 (systemd): The first process that starts all others

  • Orphaned processes: When a parent process dies, children are adopted by PID 1

Option Styles:

  1. UNIX style: Uses dash before options (e.g., -ef) - FOCUS OF THIS LESSON

  2. BSD style: No dash (e.g., aux)

  3. GNU long style: Double dash (e.g., --help)

2. The kill Command

What it does: Sends signals to processes to terminate or control them.

Default behavior: Sends SIGTERM (signal 15) - a "polite" termination request.

Key Signals:

  • SIGTERM (15): Default signal

    • Asks process to terminate gracefully

    • Allows cleanup (saving files, closing connections)

    • Process can refuse (but usually doesn't)

    • Command: kill PID or kill -15 PID

  • SIGKILL (9): Forceful termination

    • Immediately kills the process

    • NO cleanup allowed

    • Cannot be ignored by process

    • Like unplugging a computer

    • Command: kill -9 PID

Syntax: kill [signal] PID

Example:

kill 1234 # Sends SIGTERM to process 1234 kill -9 1234 # Force kills process 1234 kill -15 1234 # Explicitly sends SIGTERM

Important Notes:

  • Killing a parent doesn't automatically kill children

  • Child processes may become orphaned (adopted by PID 1)

  • Use SIGTERM first; only use SIGKILL if necessary

3. The top Command

What it does: Provides a real-time, dynamic view of running processes and system resources.

Interface Components:

Header Section:

  • Uptime: How long system has been running

  • Users: Number of logged-in users

  • Load Average: System load over 1, 5, and 15 minutes

  • Tasks: Total processes and their states (running, sleeping, stopped, zombie)

  • CPU %: CPU usage breakdown

  • Memory (Mem): RAM usage

  • Swap: Swap space usage

Process List:

  • Sorted by CPU usage by default

  • Shows: PID, USER, PR (priority), NI (nice value), VIRT, RES, SHR, S (state), %CPU, %MEM, TIME+, COMMAND

Interactive Keys:

  • h: Help menu (shows all options)

  • k: Kill a process (prompts for PID and signal)

  • q: Quit top

  • l: Toggle load average display

  • t: Toggle/cycle CPU display format

  • m: Toggle/cycle memory display format

  • w: Write current configuration to file

Killing Processes in top:

  1. Press k

  2. Enter PID (default is top process)

  3. Enter signal number (default is 15/SIGTERM)

  4. Process is terminated


Author

abdullah S.

Informationen

Zuletzt geändert