Processes & threads
Process vs thread?
A process has its own separate memory space; threads live inside a process and share its memory but keep their own stack and registers. Threads are lighter to create and switch between.
What are process states and the PCB?
A process moves through new, ready, running, waiting and terminated states. The Process Control Block stores its state, program counter, registers and other metadata the OS needs to manage it.
Why does a context switch have a cost?
Switching the CPU from one process/thread to another means saving the current one's state and loading the next one's - pure overhead during which no useful work happens.
How do processes communicate (IPC)?
Through mechanisms like pipes, shared memory and message passing, since processes don't share memory by default.
Scheduling & synchronization
Explain FCFS, SJF and Round Robin.
FCFS runs processes in arrival order (simple but suffers the convoy effect). SJF runs the shortest job next (optimal average waiting time but needs burst prediction). Round Robin gives each process a fixed time slice (fair, good for time-sharing). Be ready to compute waiting and turnaround times.
What is a race condition and the critical section?
A race condition is when the result depends on the timing of threads accessing shared data. The critical section is the code accessing that shared data, which must run with mutual exclusion.
Semaphore vs mutex, and the producer-consumer problem?
A mutex is a lock owned by one thread at a time; a semaphore is a counter controlling access to a number of permits. The producer-consumer problem uses them to coordinate a bounded buffer so producers wait when it's full and consumers wait when it's empty.
What are the four conditions for deadlock?
Mutual exclusion, hold-and-wait, no preemption, and circular wait - all four must hold. Break any one (e.g. impose a lock ordering to remove circular wait) to prevent deadlock; Banker's algorithm avoids unsafe states.
Memory management
Paging vs segmentation?
Paging splits memory into fixed-size frames, eliminating external fragmentation. Segmentation divides memory into variable-size logical units (code, stack, data) that match program structure but can fragment.
Explain virtual memory, page faults and replacement algorithms.
Virtual memory lets a program use more address space than physical RAM by paging to disk. A page fault occurs when a referenced page isn't in memory and must be loaded; FIFO, LRU and Optimal decide which page to evict when memory is full.
What is thrashing?
When processes don't have enough frames, the system spends most of its time paging in and out rather than executing. Fix it by reducing the degree of multiprogramming or adding memory.
