# Processes ## What a process actually is A **process** is a running instance of a program — its own code, its own private memory, and a unique identifier the kernel tracks called a **PID** (Process ID). Run the same program twice (open two terminals both running `bash`), and you get two separate processes with two different PIDs, even though they're running identical code. ## Foreground vs. background A command you run normally occupies your terminal until it finishes (**foreground**) — you can't type anything else until it's done. Append `&` to run it in the **background** instead, freeing your terminal immediately while the process keeps running. `sleep 300 &` starts a 300-second sleep in the background and hands your prompt right back. ## Inspecting processes: `ps` and `top` - `ps aux` — a snapshot of every process currently running, including its PID, how much CPU/ memory it's using, and the exact command that started it. - `top` (or `htop`, if installed) — the same idea, but live-updating and sorted by resource usage, useful for "what's actually eating CPU/memory right now." ## Stopping a process: `kill` and signals `kill ` doesn't instantly destroy a process — it sends it a **signal**, a message the process can (usually) choose how to respond to. The default signal, `SIGTERM` (15), politely asks a process to shut down, giving it a chance to clean up first. `kill -9 ` sends `SIGKILL`, which the kernel enforces immediately with no chance for the process to react — appropriate only when a process is truly stuck and ignoring `SIGTERM`. `kill -0 ` is a special case: it sends NO real signal at all, just checks whether the PID still exists — exactly how you confirm "did that process actually stop" without side effects. ## Process hierarchy Every process (except the very first one at boot) has a **parent** — the process that started it. Your shell is the parent of every command you run from it. This matters later: a parent process's own lifecycle can affect its children (this is part of why a container, which is often just one process tree, behaves the way it does when its main process exits). ## Why this matters for containers and Kubernetes A container is, underneath, mostly an isolated process (or small process tree) with its own view of the filesystem and network — when people say "a container exited," they mean its main process exited, exactly the same event you'll cause on purpose in this module's Lab. Kubernetes' entire job, at its core, is deciding which machine a process (inside a container) runs on and restarting it if it dies unexpectedly — none of that will feel intuitive without this module's model of what a process actually is. ## Instructor Notes **Lesson goal:** Build a real process mental model (PID, foreground/background, signals, parent/child) that ROOT 04 (containers) and ROOT 06 (Kubernetes workloads) both directly build on without re-explaining. **Approximate timing:** 15 minutes read; 10 minutes live. **Common misconception to watch for:** students often think `kill` always means "forcefully destroy" — clarify that plain `kill` sends a polite, ignorable request (SIGTERM), and `-9` is the forceful escalation, not the default. **Discussion question:** "What do you think happens to a container if its main process exits on its own, versus if something outside kills it?" (Don't need a complete answer yet — just plant the question for later.)