Blog
Operating System Concepts BSSE 4th Mid Past Paper 2015 – UOS Main Campus
University of Sargodha main campus (Department of Computer Science) Operating System Concepts mid-term paper for BSSE 4th (Reg + Self), session 2013-17, held on 11 April 2015. Retyped from the original paper, with solved answers below.
Question 4 was not included in the available copy of this paper.
Solved answers
Q1 (A) – Short answers
- Deadlock avoidance. The Banker’s algorithm grants a request only if the system stays in a safe state.
- Shortest Job First and Priority can cause starvation (a long or low-priority job may wait forever). FIFO and Round Robin do not.
- Always. If mutual exclusion, hold and wait, no preemption and circular wait all hold at the same time, the processes in the circular wait are deadlocked.
- No. With multiple instances of each resource type, a cycle is necessary but not sufficient. With single instances, a cycle is both necessary and sufficient.
Q1 (B) – Brief answers
1. Multi-core multi-threaded systems: a single chip has several processing cores, and each core has hardware support for two or more threads (hardware threads). When one thread stalls on a memory access, the core switches to another thread, so the cores stay busy. The OS sees every hardware thread as a logical CPU.
2. Advantage of dynamic linking: library code is linked at run time, so one copy of a shared library (DLL / .so) is kept in memory for all programs. Executables are smaller, memory is saved, and a library can be updated without relinking every program.
3. Fragmentation is memory that is free but cannot be used. Internal fragmentation is unused space inside an allocated block; external fragmentation is free space split into small non-contiguous holes. Paging suffers from internal fragmentation (the last page of a process is partly empty). Segmentation suffers from external fragmentation (variable-size segments leave holes).
Q2.1 – SJF and SRF (SRTF) scheduling
| Process | P0 | P1 | P2 | P3 | P4 | P5 |
|---|---|---|---|---|---|---|
| Arrival | 1 | 2 | 3 | 5 | 6 | 7 |
| Burst | 7 | 2 | 4 | 1 | 4 | 2 |
SJF (non-preemptive) Gantt chart: | P0 1–8 | P3 8–9 | P1 9–11 | P5 11–13 | P2 13–17 | P4 17–21 |
| Process | Completion | Turnaround (CT − AT) | Waiting (TAT − BT) |
|---|---|---|---|
| P0 | 8 | 7 | 0 |
| P1 | 11 | 9 | 7 |
| P2 | 17 | 14 | 10 |
| P3 | 9 | 4 | 3 |
| P4 | 21 | 15 | 11 |
| P5 | 13 | 6 | 4 |
Average turnaround = 55 / 6 = 9.17; average waiting = 35 / 6 = 5.83.
SRF / SRTF (preemptive) Gantt chart: | P0 1–2 | P1 2–4 | P2 4–5 | P3 5–6 | P2 6–9 | P5 9–11 | P4 11–15 | P0 15–21 |
| Process | Completion | Turnaround | Waiting |
|---|---|---|---|
| P0 | 21 | 20 | 13 |
| P1 | 4 | 2 | 0 |
| P2 | 9 | 6 | 2 |
| P3 | 6 | 1 | 0 |
| P4 | 15 | 9 | 5 |
| P5 | 11 | 4 | 2 |
Average turnaround = 42 / 6 = 7.0; average waiting = 22 / 6 = 3.67. SRF gives the lower averages, but the long job P0 waits the most.
Q2.2 – Multilevel queue model
The ready queue is split into separate queues by process type, for example (highest to lowest priority): system processes → interactive processes → interactive editing processes → batch processes → student processes. A process is permanently assigned to one queue. Each queue has its own algorithm (e.g. RR for interactive, FCFS for batch). Between queues the scheduler uses fixed priority (a lower queue runs only when all higher queues are empty) or time slicing (e.g. 80% CPU to foreground, 20% to background). In the diagram, draw the queues stacked from highest to lowest priority with arrows feeding into the CPU.
Q3 (A) – Paging
- (a) Logical address = page number + offset = 16 + 10 = 26 bits.
- (b) Frame size = page size = 210 = 1024 bytes.
- (c) Physical address = 32 bits, offset = 10 bits, so frame number = 32 − 10 = 22 bits (222 frames).
- (d) One entry per logical page = 216 = 65,536 entries.
Q3 (B) – Hardware support for segmentation
The CPU generates a logical address (s, d): segment number and offset. The segment number indexes the segment table (located by the STBR; its length is in the STLR). Each entry holds the segment limit and base. The hardware checks d < limit: if true, physical address = base + d; if false, a trap (addressing error) goes to the OS. Draw: CPU → (s, d) → segment table [limit | base] → comparator (d < limit?) → adder (base + d) → physical memory, with the “no” branch going to trap.
Q5 – Banker’s algorithm
Need = Max − Allocation: P0 (0,0,0,0), P1 (0,5,1,0), P2 (1,0,5,2), P3 (0,0,2,0), P4 (0,6,4,2).
A) Safety: Work = (1,5,2,0).
P0 need (0,0,0,0) ≤ Work → Work = (1,5,3,2)
P1 need (0,5,1,0) ≤ Work → Work = (2,5,3,3)
P3 need (0,0,2,0) ≤ Work → Work = (2,11,6,5)
P2 need (1,0,5,2) ≤ Work → Work = (3,14,6,9)
P4 need (0,6,4,2) ≤ Work → Work = (3,14,7,13)
All finish, so the system is safe. Safe sequence: <P0, P1, P3, P2, P4>.
B) Request (0,0,1,0) from P3: Request ≤ Need (0,0,2,0) ✔ and Request ≤ Available (1,5,2,0) ✔. Pretend to allocate: Available = (1,5,1,0), P3 allocation = (0,6,4,2), P3 need = (0,0,1,0). Running the safety algorithm again gives the same safe sequence <P0, P1, P3, P2, P4>, so the request can be granted immediately.
