Blog
Operating Systems Past Paper 2025 BSCS UOS
Operating Systems Past Paper 2025 BSCS UOS
Paper text and solved answers
University of Sargodha – BS 5th Semester Examination 2025 – Operating Systems (CMPC-301 / CMP-3621) – Time 2:30 hrs – Max marks 40. Objective part compulsory; attempt any three subjective questions.
Q1 – Short questions (2×8)
(i) What is meant by starvation? A process waits indefinitely because other (higher-priority or favoured) processes keep getting the resource/CPU – e.g. low-priority processes in priority scheduling. Solved by aging (gradually raising the priority of waiting processes).
(ii) What is the short-term scheduler? The CPU scheduler: it selects one process from the ready queue and allocates the CPU to it. It runs very frequently (every few milliseconds), so it must be fast. (Long-term scheduler admits jobs; medium-term swaps.)
(iii) What is a critical section? The part of a program in which a process accesses shared data/resources. Only one process may execute its critical section at a time; a solution must provide mutual exclusion, progress and bounded waiting.
(iv) Define swapping. Temporarily moving a whole process out of main memory to a backing store (disk) and later bringing it back to continue execution – allows more processes than fit in memory (done by the medium-term scheduler).
(v) What is DMA? Direct Memory Access lets a device controller transfer a block of data directly between the I/O device and main memory without CPU involvement for each byte; the CPU only sets up the transfer and is interrupted once when the whole block is done.
(vi) What is a page fault? A trap raised when a process references a page that is not currently in main memory (invalid bit in page table). The OS finds the page on disk, loads it into a free frame (replacing a page if needed), updates the page table and restarts the instruction.
(vii) What is segmentation? A memory-management scheme that divides a program into variable-sized logical units (segments) – code, data, stack, functions. A logical address is <segment-number, offset>, translated using a segment table holding base and limit.
(viii) What is deadlock? A set of processes is deadlocked when each waits for a resource held by another in the set, so none can proceed. It requires mutual exclusion, hold and wait, no preemption and circular wait.
Q2 – Preemptive priority scheduling
| Process | Arrival | Burst | Priority |
|---|---|---|---|
| P1 | 0 | 8 | 2 |
| P2 | 2 | 6 | 2 |
| P3 | 4 | 3 | 1 |
| P4 | 10 | 3 | 4 |
Low number = high priority. Ties are broken by arrival order (FCFS); a process of equal priority does not preempt the running one.
t=0 : only P1 -> P1 runs
t=2 : P2 arrives (priority 2 = P1's) -> no preemption, P1 continues
t=4 : P3 arrives (priority 1) -> preempts P1 (P1 remaining = 4)
t=7 : P3 finishes; P1 (pri 2, arrived 0) and P2 (pri 2, arrived 2) -> P1
t=10 : P4 arrives (priority 4) -> lower, no preemption
t=11 : P1 finishes -> P2 runs
t=17 : P2 finishes -> P4 runs, finishes at 20
Gantt chart:
| P1 | P3 | P1 | P2 | P4 |
0 4 7 11 17 20| Process | Completion | Turnaround (CT − AT) | Waiting (TAT − BT) |
|---|---|---|---|
| P1 | 11 | 11 | 3 |
| P2 | 17 | 15 | 9 |
| P3 | 7 | 3 | 0 |
| P4 | 20 | 10 | 7 |
Average waiting time = (3 + 9 + 0 + 7) / 4 = 19 / 4 = 4.75 ms. (Average turnaround = 39/4 = 9.75 ms.)
Q3 – Dining Philosophers problem
Five philosophers sit at a round table, alternately thinking and eating. There is a bowl of rice and five chopsticks, one between each pair. To eat, a philosopher needs both the left and right chopsticks; after eating, both are put down. It is a classic synchronisation problem representing the allocation of several resources among processes without deadlock and starvation.
Simple semaphore solution (can deadlock):
semaphore chopstick[5] = {1,1,1,1,1};
philosopher(i):
while (true) {
wait(chopstick[i]); // pick left
wait(chopstick[(i+1) % 5]); // pick right
/* eat */
signal(chopstick[i]);
signal(chopstick[(i+1) % 5]);
/* think */
}Example of the problem: if all five become hungry at the same time and each picks up the left chopstick, every chopstick is taken and each waits forever for the right one – deadlock. A philosopher may also starve if neighbours keep eating alternately.
Remedies: allow at most four philosophers at the table at once; let a philosopher pick up chopsticks only if both are available (inside a critical section/monitor); asymmetric solution – odd philosophers pick left first, even pick right first; or the monitor solution with states THINKING/HUNGRY/EATING where a philosopher eats only if neither neighbour is eating.
Q4 – Process Control Block (PCB)
The PCB (task control block) is the data structure the OS keeps for each process; it represents the process and stores everything needed to stop and later resume it. Contents:
- Process state – new, ready, running, waiting, terminated.
- Process ID (and parent ID).
- Program counter – address of the next instruction.
- CPU registers – accumulators, index registers, stack pointer, condition codes.
- CPU-scheduling information – priority, pointers to scheduling queues.
- Memory-management information – base/limit registers, page or segment tables.
- Accounting information – CPU time used, time limits, job numbers.
- I/O status information – allocated devices, list of open files.
During a context switch, the OS saves the running process’s state into its PCB and reloads the state from the next process’s PCB. PCBs are linked into the ready and device queues.
Q5 – Page replacement and FIFO
Page replacement: when a page fault occurs and no frame is free, the OS selects a victim page in memory, writes it to disk if modified (dirty bit), loads the required page into that frame, and updates the page tables. The goal is the lowest page-fault rate. Algorithms: FIFO, Optimal, LRU, LRU-approximation (clock).
FIFO: the page that has been in memory the longest (first loaded) is replaced; implemented with a queue. Simple but may replace heavily used pages, and suffers Belady’s anomaly (more frames can give more faults).
Example – reference string 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 with 3 frames (F = fault, H = hit):
Ref : 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Fr1 : 7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7
Fr2 : 0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0
Fr3 : 1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2 1
F F F F H F F F F F F H H F F H H F F FTotal page faults = 15 (hits = 5), fault rate 15/20 = 75%.
Q6 – Files and access methods
A file is a named collection of related information recorded on secondary storage; it is the smallest unit of logical storage seen by the user. It has attributes (name, type, location, size, protection, time stamps) and operations (create, open, read, write, reposition/seek, delete, truncate).
Sequential access: records are processed in order, one after another; read next advances the file pointer, write next appends, and the pointer can only be reset to the beginning (or skip n records). Based on the tape model. Used by editors, compilers, log files. Simple, but slow to reach a record in the middle.
Direct (relative/random) access: the file is viewed as a numbered sequence of fixed-length blocks/records, and any block can be read or written in any order: read n, write n, or seek(n) then read. Based on the disk model. Used for databases and airline reservation systems where immediate access to large amounts of information is needed. Sequential access can be simulated on direct access by keeping a current-position pointer.
Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.
