← Interview Prep

Linux Kernel — Processes & Threads

The Linux task model: task_struct (pid/tgid, state, mm, files, signals), process states mapped to ps letters, fork with Copy-On-Write, clone flags (threads = CLONE_VM), kernel threads, the process tree/reparenting, and exit/zombies.

What a "process" actually is inside the kernel, how threads fit, and how the whole tree comes to life from fork. Original, interview-focused notes on the Linux process model.

In Linux there's really one abstraction: a task (struct task_struct). A "process" and a "thread" are both tasks — the difference is just what they share. Threads of a process share the same address space (mm), files, and signal handlers; separate processes don't.

The process descriptor

Every task is a task_struct holding its entire context: identity, state, and pointers to shared resources.

Field (concept)What it holds
pid / tgidThe thread ID and the thread-group IDtgid is what userspace calls the "PID". All threads of a process share one tgid.
stateRun state (below).
mmAddress space (page tables, VMAs). Shared by threads; NULL for kernel threads.
files, fsOpen file descriptors, cwd/root.
signal / sighandSignal state & handlers.
parent / childrenThe process tree.
sched fieldsPriority, vruntime, scheduling class (see Scheduling).

Each task also has a small kernel stack with a thread_info; current always points at the running task's descriptor.

Process states

StateMeaning
TASK_RUNNING (R)Running or runnable (on a run queue).
TASK_INTERRUPTIBLE (S)Sleeping, wakeable by a signal or event.
TASK_UNINTERRUPTIBLE (D)Sleeping in a syscall (usually I/O); signals don't wake it — the "won't die" case.
__TASK_STOPPED (T)Stopped (SIGSTOP / ptrace).
EXIT_ZOMBIE (Z)Exited, waiting for the parent to wait() and reap the exit status.

These map exactly to the ps letters — see the zombie vs D-state troubleshooting case.

Creating tasks: fork / clone

The tree, kernel threads, and exit

Likely interview questions

Kernel Internals series. Related: Scheduling · Linux Troubleshooting.