CS CS Operating Systems & Memory Management 2 — Questions and Answers
Question 1: What is the purpose of a semaphore in concurrent programming?
- To allocate virtual memory pages to processes
- To synchronize access to shared resources by controlling how many threads can access a section simultaneously (Correct answer)
- To schedule threads based on priority
- To measure CPU utilization across cores
Correct answer: To synchronize access to shared resources by controlling how many threads can access a section simultaneously
A semaphore is an integer-based synchronization primitive that uses wait (P) and signal (V) operations to control concurrent access to shared resources.
Question 2: In memory management, what is 'fragmentation'?
- The process of splitting a file across multiple disk sectors
- Wasted memory space that cannot be used due to how memory allocations are laid out (Correct answer)
- A technique to speed up memory access by caching frequently used addresses
- The breaking of large pages into smaller pages to support fine-grained access control
Correct answer: Wasted memory space that cannot be used due to how memory allocations are laid out
Fragmentation refers to memory that is technically free but unusable — external fragmentation is unusable space between allocations, and internal fragmentation is wasted space within allocations.
Question 3: What is the role of the Translation Lookaside Buffer (TLB) in a virtual memory system?
- It stores recently accessed disk blocks to speed up I/O
- It caches recent virtual-to-physical address translations to speed up memory access (Correct answer)
- It holds the process control blocks for all running processes
- It maps system calls to kernel function addresses
Correct answer: It caches recent virtual-to-physical address translations to speed up memory access
The TLB is a fast hardware cache that stores recent page table entries, allowing virtual-to-physical address translation without a full page table lookup on most accesses.
Question 4: What condition must be broken to prevent deadlock according to the Coffman conditions?
- Preemption, Circular Wait, Mutual Exclusion, or Hold and Wait — at least one must be broken (Correct answer)
- Only circular wait needs to be broken
- Only mutual exclusion needs to be eliminated
- Deadlock can only be prevented by killing all waiting processes
Correct answer: Preemption, Circular Wait, Mutual Exclusion, or Hold and Wait — at least one must be broken
Deadlock requires all four Coffman conditions simultaneously; preventing any one of them (mutual exclusion, hold-and-wait, no preemption, or circular wait) is sufficient to avoid deadlock.
Question 5: What is 'thrashing' in the context of virtual memory?
- Excessive disk I/O caused by a process continuously page faulting because its working set does not fit in RAM (Correct answer)
- A CPU scheduling condition where too many processes run simultaneously
- Repeated context switches triggered by high-priority interrupts
- Memory corruption caused by buffer overflow attacks
Correct answer: Excessive disk I/O caused by a process continuously page faulting because its working set does not fit in RAM
Thrashing occurs when a system spends more time handling page faults and swapping pages than executing actual process instructions, severely degrading performance.
Question 6: In Unix-like operating systems, what is a 'zombie process'?
- A process that has exceeded its CPU quota and is suspended
- A process that has terminated but whose exit status has not yet been collected by its parent (Correct answer)
- A process blocked on I/O indefinitely
- A daemon process running with no controlling terminal
Correct answer: A process that has terminated but whose exit status has not yet been collected by its parent
A zombie process has completed execution but remains in the process table until its parent calls wait() to retrieve its exit status and free its entry.
What is the purpose of a semaphore in concurrent programming?