Level 1: Bronze
A memorized definition. Not wrong, but it stops there.
It is when the CPU changes which process it runs.
2 stars Asked often.
In one or two sentences
The CPU saves the state of the task it was running, loads the state of another task and continues there. While that happens, the CPU does no user work.
Say it out loud, or type it below. What you type never leaves this device.
A memorized definition. Not wrong, but it stops there.
It is when the CPU changes which process it runs.
Correct, but too broad or missing context.
The OS saves the running process's registers and program counter in its PCB, then loads the next process's state. No real work is done in between, so it is overhead.
Reaches principle, use and trade-off, with words that invite the next question.
When a time slice ends or a task blocks on I/O, the kernel saves the current context in the PCB and restores the next one. The direct cost is saving and restoring. The indirect cost is larger: a new address space means the TLB must be flushed or refilled, and the caches go cold for a while. Switching between threads of one process keeps the address space, so it is cheaper. Switch too often and throughput drops. Switch too rarely and responsiveness drops.
These are likely next questions from an interviewer. Think of your answer first, then press the button.
1 / 3
Which is more expensive, a process switch or a thread switch?
A process switch. The address space changes, so you lose TLB and cache warmth. Threads of one process keep the same address space.
2 / 3
When does a context switch happen?
When a time slice ends, when a task blocks on I/O or a lock, or when a higher priority task wakes up.
3 / 3
What does a PCB hold?
The process id and state, the program counter, register values, scheduling info, memory management info and the list of open files.
This is a textbook level concept, so no outside source is listed.