Galle, LK--:--5/6 sites live

Linux Process Management, Job Control & POSIX Signals

පිටුව 05: Linux Process කළමනාකරණය, Job Control සහ POSIX Signals (kill -9 vs -15)

Process එකක් කියන්නේ මොකක්ද? PID, PPID, Process States (R, S, D, Z Zombie), Foreground/Background (&), සහ kill Signals (SIGTERM vs SIGKILL).

6 Sept 20264 min readSelf Guide · Stage 10#Processes#Signals#SRE Labs

Lab 05 of 20 · Processes & Signals · 5 hands-on activities · bilingual (English + සිංහල)

පිටුව 05: Linux Process කළමනාකරණය, Job Control සහ POSIX Signals (kill -9 vs -15)

Process එකක් කියන්නේ මොකක්ද? PID, PPID, Process States (R, S, D, Z Zombie), Foreground/Background (&), සහ kill Signals (SIGTERM vs SIGKILL).

💡 සරල සිංහලෙන්: Zombie Process සහ kill -9 සහ kill -15 අතර වෙනස

Zombie Process කියන්නේ මොකක්ද?

දරුවෙක් තමන්ගේ වැඩේ ඉවර කරලා ගෙදර ඇවිත් මැරුණා වගේ! හැබැයි අම්මා/තාත්තා (Parent process) ඒක දන්නේ නෑ. ඒ නිසා Process එක RAM එකේ ඉඩ නොගත්තත් Process Table එකේ නම රැඳිලා තියෙනවා. මේකට තමයි Zombie process (Z state) කියන්නේ.

kill -15 (SIGTERM) vs kill -9 (SIGKILL):

  • kill -15 (කාරුණිකව කියන එක): "අපි ඔයාව නවත්වන්න හදන්නේ, ඒ නිසා කර කර හිටපු වැඩ save කරලා, database connections වහලා පිළිවෙලට වැහෙන්න" කියලා දැනුම් දෙන එක. හැමවිටම මුලින්ම පාවිච්චි කරන්න ඕන මේකයි.
  • kill -9 (හිස ගසා දැමීම): Process එක හිරවෙලා කිසිම ප්‍රතිචාරයක් දෙන්නේ නැත්නම්, Kernel එක කෙලින්ම ගිහින් කිසිම අවසරයක් නැතුව ඒක ක්ෂණිකව මරලා දාන එක. Data corrupt වෙන්න පුළුවන් නිසා අන්තිම විසඳුම විදියට විතරක් පාවිච්චි කරන්න!

Architectural Foundation & Systems Diagram

A Process is simply an executing instance of an application loaded into memory. Every process in Linux has a unique PID (Process ID) and a parent that spawned it (PPID).

  • 🧬 Process States — • R (Running): Executing on a CPU core.
    • S (Interruptible Sleep): Waiting for event/I/O.
    • D (Uninterruptible Sleep): Blocked on disk I/O.
    • Z (Zombie): Terminated, but parent hasn't read exit status!

  • 🛑 SIGTERM (15) vs SIGKILL (9) — kill -15 (SIGTERM): Polite request. The app can catch the signal, finish database transactions, flush logs, and close sockets safely.
    kill -9 (SIGKILL): Brutal execution by the kernel. The app cannot catch or ignore it; it is obliterated instantly, risking data corruption.

  • ⚡ Job Control (&, fg, bg, jobs) — Append & to run commands in the background without locking your shell. Press Ctrl+Z to suspend a running process, and type bg to resume it in background or fg to bring it back!

Step-by-step practical lab

Step 01: Inspect Active User ID & Group Memberships

සිංහලෙන් — අපේ පරිශීලක හැඳුනුම්පත (UID) සහ Groups පරීක්ෂා කරමු.

Print real and effective user ID (UID), primary group ID (GID), and all supplementary group memberships.

ExampleShell
id
  • id : UID, GID සහ සම්බන්ධ සියලුම Security Groups පෙන්වයි.

Expected output

Output
uid=1000(sre-engineer) gid=1000(sre-engineer) groups=1000(sre-engineer),4(adm),27(sudo),998(docker)

SRE Tip: In Linux, UID 0 is reserved exclusively for the root superuser. Standard interactive users typically start at UID 1000.

Step 02: Modify File Permissions with Octal Notation

සිංහලෙන් — File එකකට Read, Write, Execute (rwx) permissions ලබා දෙමු.

Set Read/Write/Execute permissions for Owner (7 = rwx), and Read/Execute for Group and Others (5 = r-x).

ExampleShell
chmod 755 scripts/deploy.sh
  • 755 : 7 (rwx) අයිතිකරුට; 5 (r-x) සමූහයට (group); 5 (r-x) අනෙක් අයට (others).

Expected output

Output
-rwxr-xr-x 1 sre-engineer devops 1280 Sep 16 12:45 scripts/deploy.sh

SRE Tip: Never run chmod 777 in production! It gives every user and rogue process write access to modify your code.

Hands-on practice activities

Work through these yourself — tick them off as you go.

  • Activity 21: Query Full Process Table Snapshot (Drill) — List all processes running across the system with user, PID, %CPU, %MEM, and command name.
  • Activity 22: Launch Real-Time System Monitor (Drill) — Inspect real-time CPU task scheduling, memory consumption, and load averages.
  • Activity 23: Send Graceful SIGTERM Signal to PID (Drill) — Transmit SIGTERM to PID 1042 requesting orderly termination and graceful resource cleanup.
  • Activity 24: Force Terminate Unresponsive Process (Drill) — Transmit uncatchable SIGKILL to immediately destroy a hung zombie or runaway task.
  • Activity 25: Uncatchable Signal Quiz (Quiz) — Which signal CANNOT be caught, handled, or ignored by any user-space application? Answer: SIGKILL (Signal 9).

Keep going: ← Lab 04 · Lab 06 → · Track your progress in the Self Guide

ExerciseKnowledge check

Which signal CANNOT be caught, handled, or ignored by any user-space process? / කිසිදු application එකකට catch හෝ ignore කළ නොහැකි signal එක කුමක්ද?

Finished this one?

Part of Self Guide · Stage 10: SRE Labs I — the machine underneath. Progress is saved in this browser.

Guide