Started okay with address space isolation and task_struct, but when they pushed on clone() flags and exactly how threads share memory vs processes I got a bit fuzzy.
Structure your answer by contrasting processes and threads across the six dimensions the interviewer listed, using a consistent comparison framework. Start with the fundamental memory isolation difference, then move through scheduling, file descriptors, signals, and context switch overhead, and finish with practical guidance on when to choose each. Keep the explanation grounded in concrete Linux examples (e.g., fork/clone, pthreads) to show depth without overcomplicating.
Pro tip: Mention that Linux doesn't inherently distinguish processes and threads—both are tasks created via clone() with different flags—and that the real difference is which resources are shared. This shows you understand the kernel implementation, not just textbook definitions.
Explain that a process is an independent execution unit with its own virtual address space, while a thread is a lighter execution unit within a process that shares the address space and other resources. Note that in Linux both are represented as tasks and created via clone().
Describe how processes have separate memory (copy-on-write after fork) and separate file descriptor tables, while threads share memory and file descriptors by default. Mention that threads can still have thread-local storage and that file descriptor sharing means closing a file in one thread affects all.
State that the Linux CFS scheduler schedules threads (tasks) individually, not processes as a whole, so threads within a process can run concurrently on different CPUs. For signals, explain that process-directed signals can be handled by any thread that doesn't block them, while thread-directed signals (e.g., from pthread_kill) go to a specific thread.
Contrast the cost: a thread context switch within the same process is cheaper because it avoids switching page tables (no TLB flush), while a process context switch requires changing the address space and flushing TLB entries, making it more expensive. Note that both still involve kernel mode transitions and saving/restoring registers.
Conclude with when to use each: processes for isolation, fault tolerance, and security (e.g., separate services); threads for performance, shared state, and low-latency communication (e.g., parallel computation, I/O multiplexing). Mention that modern designs often use a hybrid (e.g., process pools with thread pools) or async I/O to avoid thread overhead.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.