B CompE Bachelor of Computer Engineering Bachelor of Computer Engineering Operating System 5 — Questions and Answers
Question 1: What is the purpose of a 'context switch' in a multitasking OS?
- Moving data between user and kernel space
- Saving one process's CPU state and restoring another's to allow time-sharing (Correct answer)
- Switching between kernel and user mode
- Transferring control from one CPU core to another
Correct answer: Saving one process's CPU state and restoring another's to allow time-sharing
A context switch saves the current process's registers, program counter, and stack pointer, then restores the saved state of the next scheduled process.
Question 2: Which I/O technique allows a device to transfer data directly to/from memory without CPU involvement on every byte?
- Programmed I/O (polling)
- Interrupt-driven I/O
- Direct Memory Access (DMA) (Correct answer)
- Memory-mapped I/O
Correct answer: Direct Memory Access (DMA)
DMA offloads bulk data transfers to a dedicated controller, freeing the CPU to execute other instructions while the transfer completes.
Question 3: In a two-level page table, why is the outer (directory) page table needed?
- To eliminate TLB misses
- To avoid allocating a large contiguous page table for sparse address spaces (Correct answer)
- To support segmentation
- To speed up disk access
Correct answer: To avoid allocating a large contiguous page table for sparse address spaces
A two-level page table splits the virtual address into two indices, allowing unallocated portions of the address space to skip allocating second-level tables entirely.
Question 4: Which RAID level mirrors data across two disks, providing fault tolerance but halving usable capacity?
- RAID 0
- RAID 1 (Correct answer)
- RAID 5
- RAID 6
Correct answer: RAID 1
RAID 1 writes identical data to two disks simultaneously; if one fails, the other contains a complete copy, but only 50% of total disk capacity is usable.
Question 5: What mechanism does the OS use to protect the kernel from direct access by user-mode programs?
- Segmentation fault trapping
- Privileged (ring) CPU modes enforced by hardware (Correct answer)
- Sandboxing via virtual machines
- Memory encryption
Correct answer: Privileged (ring) CPU modes enforced by hardware
Modern CPUs implement privilege rings (typically ring 0 for kernel, ring 3 for user), and the hardware blocks user-mode code from executing privileged instructions.
Question 6: In the Producer-Consumer problem solved with semaphores, which semaphore tracks the number of empty buffer slots?
- mutex
- full
- empty (Correct answer)
- count
Correct answer: empty
The 'empty' semaphore is initialized to the buffer size and decremented by the producer before inserting an item, blocking it when no slots are available.
Question 7: Which file system journaling mode offers the strongest consistency guarantee by logging both metadata and data before committing?
- Writeback mode
- Ordered mode
- Full journaling mode (Correct answer)
- Lazy journaling mode
Correct answer: Full journaling mode
Full (data) journaling writes both file data and metadata to the journal before committing to the main file system, ensuring complete consistency after a crash.
What is the purpose of a 'context switch' in a multitasking OS?