Operating Systems
Level: 2 (Recall — definitions, standard problems, short derivations) Time limit: 30 minutes Total marks: 50
Q1. State the three core roles of an operating system in one line each. (3 marks)
Q2. List the four Coffman conditions that must all hold simultaneously for a deadlock to occur. (4 marks)
Q3. A process transitions through five states. Name each state and give the event that causes each of these two transitions: Running → Ready and Running → Blocked. (5 marks)
Q4. Explain the difference between internal and external fragmentation. Which one does paging eliminate, and why? (4 marks)
Q5. Given the following processes with arrival time 0, compute the average waiting time and average turnaround time under FCFS scheduling. (6 marks)
| Process | Burst Time |
|---|---|
| P1 | 5 |
| P2 | 3 |
| P3 | 8 |
Order of arrival: P1, P2, P3.
Q6. Consider four processes with the following arrival and burst times. Compute the average waiting time using non-preemptive SJF. (6 marks)
| Process | Arrival | Burst |
|---|---|---|
| P1 | 0 | 6 |
| P2 | 1 | 4 |
| P3 | 2 | 2 |
| P4 | 3 | 3 |
Q7. Define a race condition and a critical section. State the three requirements a correct critical-section solution must satisfy. (5 marks)
Q8. A logical address space uses 32-bit addresses with a page size of 4 KB. Compute: (a) the number of bits for the page offset, (b) the number of bits for the page number, (c) the total number of entries in a single-level page table. (6 marks)
Q9. For a disk with the request queue 98, 183, 37, 122, 14, 124, 65, 67 and the head starting at cylinder 53, compute the total head movement under FCFS disk scheduling. (6 marks)
Q10. Distinguish between the fork() and exec() system calls in terms of what each does to the process image. (5 marks)
End of paper
Answer keyMark scheme & solutions
Q1. (3 marks)
- Resource management: allocates and schedules CPU, memory, I/O among competing processes. (1)
- Hardware abstraction: presents a clean, uniform interface (system calls) hiding hardware details. (1)
- Protection/isolation: prevents processes from interfering with each other or the kernel (dual-mode operation). (1)
Q2. (4 marks) — 1 mark each:
- Mutual exclusion — at least one resource held in non-shareable mode.
- Hold and wait — a process holds resources while waiting for others.
- No preemption — resources cannot be forcibly taken away.
- Circular wait — a cycle of processes each waiting on the next.
Q3. (5 marks) States (1 mark for all five): New, Ready, Running, Blocked (Waiting), Terminated. (1)
- Running → Ready: caused by a timer interrupt / time-quantum expiry / preemption (process still runnable). (2)
- Running → Blocked: caused by an I/O request or waiting on an event/resource. (2)
Q4. (4 marks)
- Internal fragmentation: wasted space inside an allocated block/page because the allocation is rounded up to a fixed unit larger than needed. (1.5)
- External fragmentation: free memory exists but is split into non-contiguous small holes that cannot satisfy a request. (1.5)
- Paging eliminates external fragmentation because any free frame can hold any page — allocation need not be contiguous. (Internal fragmentation remains, in the last page.) (1)
Q5. (6 marks) FCFS Order P1(5), P2(3), P3(8). Completion: P1=5, P2=8, P3=16. Waiting = start time (arrival 0): P1=0, P2=5, P3=8. (2) Average waiting = . (2) Turnaround = completion: P1=5, P2=8, P3=16 → avg = . (2)
Q6. (6 marks) Non-preemptive SJF
- t=0: only P1 available → run P1 (0→6). (1)
- t=6: available P2(4),P3(2),P4(3) → shortest P3 (6→8). (1)
- t=8: P2(4),P4(3) → P4 (8→11). (1)
- t=11: P2 (11→15). (1)
Waiting = start − arrival:
- P1: 0−0 = 0
- P3: 6−2 = 4
- P4: 8−3 = 5
- P2: 11−1 = 10 (1)
Average waiting = . (1)
Q7. (5 marks)
- Race condition: outcome depends on the non-deterministic timing/interleaving of concurrent accesses to shared data. (1.5)
- Critical section: a code segment accessing shared resources that must not be executed by more than one process at a time. (1.5)
- Requirements (0.67 each): Mutual exclusion, Progress (only contenders decide, no indefinite postponement), Bounded waiting (bound on times others enter before a waiting process). (2)
Q8. (6 marks)
- (a) Page size 4 KB = → offset = 12 bits. (2)
- (b) Page number = 20 bits. (2)
- (c) Entries = entries. (2)
Q9. (6 marks) FCFS disk Sequence from 53: 53→98→183→37→122→14→124→65→67. Movements: |98−53|=45, |183−98|=85, |37−183|=146, |122−37|=85, |14−122|=108, |124−14|=110, |65−124|=59, |67−65|=2. (3) Sum = 45+85+146+85+108+110+59+2 = 640 cylinders. (3)
Q10. (5 marks)
fork(): creates a new child process by duplicating the calling process; child gets a copy of the parent's address space (returns 0 to child, child PID to parent). No new program is loaded. (2.5)exec(): replaces the current process's memory image with a new program (code, data, stack); PID stays the same, old image is discarded. (2.5)
[
{"claim":"Q5 FCFS average waiting time = 13/3","code":"w=[0,5,8]; result = (sum(w)/3 == Rational(13,3))"},
{"claim":"Q5 FCFS average turnaround = 29/3","code":"t=[5,8,16]; result = (sum(t)/3 == Rational(29,3))"},
{"claim":"Q6 SJF average waiting = 19/4","code":"w=[0,4,5,10]; result = (sum(w)/4 == Rational(19,4))"},
{"claim":"Q8 page table entries = 2**20","code":"result = (2**(32-12) == 1048576)"},
{"claim":"Q9 FCFS total head movement = 640","code":"seq=[53,98,183,37,122,14,124,65,67]; result = (sum(abs(seq[i+1]-seq[i]) for i in range(len(seq)-1)) == 640)"}
]