CS CS Operating Systems & Memory Management 1 — Questions and Answers
Question 1: What is a deadlock in operating systems?
- A process that consumes 100% CPU without terminating
- A situation where two or more processes wait indefinitely for resources held by each other (Correct answer)
- A memory allocation error causing a page fault
- A kernel panic caused by a device driver
Correct answer: A situation where two or more processes wait indefinitely for resources held by each other
Deadlock occurs when a set of processes are each waiting for a resource held by another process in the set, so none can proceed.
Question 2: Which page replacement algorithm replaces the page that will not be used for the longest time in the future?
- FIFO (First-In, First-Out)
- LRU (Least Recently Used)
- OPT (Optimal) (Correct answer)
- Clock Algorithm
Correct answer: OPT (Optimal)
The Optimal (OPT) algorithm is theoretically perfect but impractical because it requires future knowledge of which pages will be accessed next.
Question 3: What is the difference between a process and a thread?
- A thread has its own memory space while a process shares memory with others
- A process is an independent execution unit with its own memory space, while threads share memory within a process (Correct answer)
- Threads cannot run in parallel on multi-core CPUs
- Processes are lighter weight than threads
Correct answer: A process is an independent execution unit with its own memory space, while threads share memory within a process
A process has its own isolated memory space, while threads within the same process share the same heap and data segments, making inter-thread communication faster but requiring synchronization.
Question 4: What does a context switch entail in an operating system?
- Switching the CPU from user mode to kernel mode
- Saving the state of a running process and restoring the state of another so the CPU can switch tasks (Correct answer)
- Allocating a new memory page for a process
- Flushing the disk write cache to storage
Correct answer: Saving the state of a running process and restoring the state of another so the CPU can switch tasks
A context switch saves the CPU registers and process state of the current process to its PCB and loads the saved state of the next scheduled process.
Question 5: In virtual memory, what is a 'page fault'?
- A hardware error in the physical RAM chips
- An interrupt triggered when a process accesses a page not currently loaded in physical memory (Correct answer)
- A bug in a process that causes an illegal memory write
- An overflow of the page table beyond available address space
Correct answer: An interrupt triggered when a process accesses a page not currently loaded in physical memory
A page fault occurs when a process references a virtual memory page that is not currently mapped to a physical frame, causing the OS to load it from disk.
Question 6: Which CPU scheduling algorithm provides the best average waiting time for a given set of processes?
- Round Robin
- First-Come First-Served (FCFS)
- Shortest Job First (SJF) (Correct answer)
- Priority Scheduling
Correct answer: Shortest Job First (SJF)
SJF minimizes average waiting time by always executing the process with the shortest expected CPU burst next, which is optimal for batch workloads.
What is a deadlock in operating systems?