Blog
Operating System BSIT 4th Term Past Paper 2014 UOS
University of Sargodha Operating System (CMP-320) past paper for BS IT 4th term 2014 (session 2012-16), with solved answers below.
Solved answers
Q1 – Short questions
(1) Purpose of system calls: they provide the interface between a running program and the operating system, letting user programs request OS services such as file operations, process creation, I/O and memory allocation in kernel mode.
(2) Threads: a thread is the basic unit of CPU utilisation — a thread ID, program counter, register set and stack — that shares code, data and open files with other threads of the same process (a lightweight process).
(3) PCB: the Process Control Block is the data structure the OS keeps for every process: state, program counter, CPU registers, scheduling information, memory-management information, accounting and I/O status.
(4) Process states: new, ready, running, waiting (blocked) and terminated.
(5) Preemptive: the OS can take the CPU away from a running process (e.g. when its time slice ends or a higher-priority process arrives) and give it to another process.
(6) Safe state: a state in which the system can allocate resources to every process in some order (a safe sequence) and still avoid deadlock.
(7) Semaphore: an integer variable accessed only through atomic wait() and signal() operations, used for mutual exclusion and process synchronisation.
(8) Deadlock: a situation where a set of processes are blocked forever because each holds a resource and waits for a resource held by another process in the set.
(9) Mutual exclusion condition: at least one resource must be held in a non-sharable mode — only one process can use it at a time; it is one of the four necessary conditions for deadlock.
(10) Swapping: temporarily moving a process from main memory to a backing store (disk) and later bringing it back to continue execution, so more processes can share memory.
(11) Paging: a memory-management scheme that divides logical memory into fixed-size pages and physical memory into frames of the same size, mapping pages to frames through a page table; it avoids external fragmentation.
(12) Cause of page fault: a process references a page that is not currently in main memory (its page-table entry is marked invalid), so the OS must load it from disk.
Q2 (a) – Operating system components and role
Components: process management (create, schedule, terminate, synchronise processes), main-memory management (allocate and free memory, track usage), file management (files and directories), I/O system management (device drivers, buffering, caching, spooling), secondary-storage management (free-space management, disk scheduling), networking, protection and security, and the command interpreter/user interface.
Role of the OS: acts as an intermediary between users and hardware; as a resource allocator it manages CPU, memory and devices fairly and efficiently; as a control program it controls the execution of programs to prevent errors and improper use; and it provides a convenient environment for running programs.
Q2 (b) – Operating-system services
User interface (GUI, command line, batch); program execution; I/O operations; file-system manipulation; communications (shared memory or message passing); error detection; resource allocation; accounting; and protection and security.
Q3 – Paging vs segmentation: memory needed for address translation
- Paging: each process needs a page table with one entry per page of its logical address space. For large address spaces this table is big (e.g. a 32-bit address space with 4 KB pages has 2²⁰ entries ≈ 4 MB per process), so multi-level or inverted page tables are used. Each entry stores a frame number and a few bits.
- Segmentation: each process needs a segment table with one entry per segment — usually only a few segments (code, data, stack, heap) — and each entry stores a base and a limit. The table is therefore very small.
- Conclusion: segmentation requires much less memory for its translation structure, while paging requires a larger table but avoids external fragmentation. Segmentation with paging combines both.
Q4 – Conditions that ensure deadlock will not occur (prevention)
Deadlock needs all four conditions together; preventing any one of them prevents deadlock:
- Mutual exclusion: make resources sharable where possible (e.g. read-only files); not possible for printers.
- Hold and wait: require a process to request all resources at once before starting, or to release all held resources before requesting new ones.
- No preemption: if a process holding resources requests one that cannot be granted, it releases its held resources (or the OS preempts them).
- Circular wait: impose a total ordering on resource types and require processes to request resources only in increasing order.
Alternatively, deadlock avoidance (Banker’s algorithm) grants requests only if the system stays in a safe state.
Q5 – Resource-allocation graph: wait-for graph and deadlock
From the graph: R1 (2 instances) is assigned to P2 and P3; R2 (2 instances) is assigned to P1 and P4; R3 (2 instances) is assigned to P2 and P3. Requests: P1 → R1, P3 → R2, P4 → R3. P2 requests nothing.
(i) Wait-for graph (remove resource nodes; Pi → Pj if Pi waits for a resource held by Pj): P1 → P2, P1 → P3; P3 → P1, P3 → P4; P4 → P2, P4 → P3. P2 has no outgoing edge.
(ii) No deadlock. Although there are cycles (e.g. P1 → P3 → P1), each resource has two instances, so a cycle is necessary but not sufficient. P2 is not waiting for anything, so it can finish and release one instance of R1 and one of R3. Then P1 gets R1 and P4 gets R3; both can finish and release R2. Finally P3 gets R2 and finishes. A safe completion sequence exists: P2 → P1 → P4 → P3, so the system is not deadlocked.
Q6 – Round robin (quantum = 2), all processes arriving at time 0
Gantt chart (in order P1…P6, 2 units each): P1 0–2, P2 2–4, P3 4–6, P4 6–7, P5 7–9, P6 9–11, P1 11–13, P2 13–15, P3 15–17, P5 17–19, P6 19–21, P1 21–23, P2 23–24, P5 24–26, P6 26–28, P1 28–30, P5 30–31, P6 31–33, P1 33–35.
| Process | Burst | Completion | Waiting time (= completion − burst) |
|---|---|---|---|
| P1 | 10 | 35 | 25 |
| P2 | 5 | 24 | 19 |
| P3 | 4 | 17 | 13 |
| P4 | 1 | 7 | 6 |
| P5 | 7 | 31 | 24 |
| P6 | 8 | 33 | 25 |
Average waiting time = (25 + 19 + 13 + 6 + 24 + 25) / 6 = 112 / 6 ≈ 18.67 units.
Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.
