2. Processes and threads
One-liner. A process owns an address space; threads share it and own only a stack and registers.
Memorize
- Process = address space + file descriptors + credentials + signal handlers + threads.
- Thread = register state + stack + TLS; shares heap, code, fds with siblings.
- Linux schedules tasks; a thread is a task with
CLONE_THREAD, so processes and threads are the same primitive. fork()copies page tables with copy-on-write;execve()replaces the image.- States: R running/runnable, S interruptible sleep, D uninterruptible (I/O), Z zombie, T stopped.
- Context switch = save/restore registers + switch address space (CR3) + TLB effects.
- Threads are cheaper to create and switch than processes, but a crash or leak is shared.
Trap. Assuming D state is killable — uninterruptible sleep ignores signals until the I/O completes. Do this. Investigate the device/FS behind D-state tasks instead of escalating signals.
Check
What is shared between two threads of the same process?
Why
Threads share the process address space and resources; each has its own stack and register context.