Blog
Operating System Past Paper 2017 – BSSE 4th Term UOS (COMP-3621)
University of Sargodha (UOS) BSSE 4th term Operating System (COMP-3621) past paper 2017 – clean printable paper, text version and solved answers, including all four Gantt charts with average waiting and turnaround times.
Print / download (A4, high quality): Full-size paper
University of Sargodha
B.S. 4th Term Examination 2017
Subject: Software Engineer
Paper: Operating System (COMP-3621)
Time Allowed: 2.30 Hours
Maximum Marks: 60
Objective Part
(Compulsory)
Q. No. 1. Write short answers of the following in 2-3 lines on your answer sheet. (2*12)
i. What are the main purposes of an operating system?
ii. What is the purpose of system Calls?
iii. What is PCB?
iv. What is multithreading?
v. What is critical section?
vi. What is meant by the term dispatch latency?
vii. Write four necessary conditions for a deadlock to exist.
viii. Name two differences between logical and physical addresses
ix. What is virtual memory?
x. What is the cause of thrashing?
xi. What is a garbage collection?
xii. What is a disk controller?
Subjective Part
(3 * 12 = 36)
Q2. Explain different models of multithreading in detail.
Q3. What is the difference between paged and segmented memory management? Explain the difference by giving a suitable example of each.
Q4. What is Deadlock? Explain in detail how deadlock can be prevented?
Q5. Define File? Explain Access Methods in files.
Q6. Consider the following set of processes:
Processes are assumed to arrive in the order P1, P2, P3, P4, P5, and P6 all at time 0.
Use FCFS, SJF, Round Robin (quantum 2), and Priority (low numbers have high priority). For each of the algorithms:
i. Draw a Gantt chart
ii. Obtain the average waiting time
iii. Obtain the average turnaround time
Original paper (scanned copy)
The clean paper above is retyped by Shining Study from this original University of Sargodha question paper. Click the scan to view it full size.
Solved answers
Q1 – Short questions
(i) An OS (1) provides a convenient environment for users to run programs (user interface, services), (2) manages and allocates resources – CPU, memory, storage, I/O – efficiently and fairly, and (3) controls programs to prevent errors and improper use (protection and security).
(ii) System calls: provide the interface through which a user program requests services from the kernel – process control, file and device management, information and communication – e.g. fork(), open(), read(), write().
(iii) PCB: the process control block is the data structure the OS keeps for each process: state, PID, program counter, CPU registers, scheduling information, memory-management information, accounting and I/O status.
(iv) Multithreading: a process has several threads of control that share its code, data and files but each has its own PC, registers and stack, so tasks can run concurrently – better responsiveness, resource sharing, economy and use of multicores.
(v) Critical section: a segment of code in which a process accesses shared data; only one process at a time may execute in its critical section (mutual exclusion, progress, bounded waiting).
(vi) Dispatch latency: the time the dispatcher takes to stop one process and start another – saving state (context switch), switching to user mode and jumping to the right location in the new program.
(vii) Mutual exclusion, hold and wait, no preemption, circular wait.
(viii) A logical (virtual) address is generated by the CPU / seen by the program; a physical address is the actual location in memory seen by the memory unit. Logical addresses are translated to physical ones at run time by the MMU (e.g. base/relocation register or page table); the logical address space can be larger than physical memory.
(ix) Virtual memory: separates logical memory from physical memory, so a program can run while only partly in RAM; pages are brought in on demand from disk, giving a very large address space and more programs in memory.
(x) Cause of thrashing: a process does not have enough frames for the pages it is actively using (its working set), so it page-faults continuously and spends more time swapping than executing; it often happens when the degree of multiprogramming is too high.
(xi) Garbage collection: automatically finding and reclaiming memory (or disk space/directory entries) that is no longer referenced by any program, e.g. in Java’s heap or in file systems with cycles in directories.
(xii) Disk controller: the electronics attached to the disk drive (with a host controller on the computer side) that receive commands from the CPU, control the drive mechanism, perform data transfer and buffering/caching, and handle bad-sector mapping.
Q2 – Multithreading models
User threads are managed by a thread library above the kernel; kernel threads are managed by the OS. Models describe how user threads map to kernel threads:
- Many-to-one: many user threads map to one kernel thread. Thread management is done in user space, so it is fast, but if one thread makes a blocking system call the whole process blocks, and threads cannot run in parallel on multiprocessors. Example: Solaris Green Threads, early GNU Portable Threads.
- One-to-one: each user thread maps to its own kernel thread. More concurrency – another thread runs when one blocks, and threads run in parallel on multicores – but creating a user thread needs a kernel thread (overhead), so the number of threads may be limited. Example: Windows, Linux.
- Many-to-many: many user threads are multiplexed onto a smaller or equal number of kernel threads. Developers can create as many user threads as needed, and kernel threads can run in parallel; when a thread blocks the kernel can schedule another. Example: older Solaris, Windows ThreadFiber.
- Two-level model: a variation of many-to-many that also allows a user thread to be bound to a kernel thread. Example: IRIX, HP-UX, Tru64.
Many-to-one One-to-one Many-to-many
U U U U U U U U U U U
\ | | / | | | \ | \ | / |
K K K K K K KQ3 – Paging vs segmentation
| Paging | Segmentation |
|---|---|
| Memory divided into fixed-size pages (logical) and frames (physical) | Program divided into variable-size logical segments (code, data, stack, functions) |
| Invisible to the programmer; done by OS/hardware | Visible to the programmer; matches the user’s view of a program |
| Address = (page number, offset) | Address = (segment number, offset) |
| Page table holds frame numbers | Segment table holds base and limit |
| No external fragmentation; internal fragmentation in the last page | No internal fragmentation; external fragmentation |
| Protection/sharing per page | Protection/sharing per logical unit (e.g. share a code segment) |
Paging example: page size 1 KB (1024 bytes); logical address 3000 → page = 3000 / 1024 = 2, offset = 3000 − 2048 = 952. If page 2 is in frame 5, physical address = 5 × 1024 + 952 = 6072.
Segmentation example: segment 2 has base 4300 and limit 400. Logical address (2, 53) → 53 < 400, so physical = 4300 + 53 = 4353. Address (2, 500) → 500 ≥ 400, so a trap (addressing error) occurs.
Q4 – Deadlock and its prevention
Deadlock: a set of processes is deadlocked when each process is waiting for a resource held by another process in the set, so none can proceed. Example: P1 holds the printer and waits for the scanner, while P2 holds the scanner and waits for the printer. It can occur only if four conditions hold at the same time: mutual exclusion, hold and wait, no preemption and circular wait.
Prevention – make sure at least one condition can never hold:
- Mutual exclusion: make resources sharable where possible (read-only files can be shared). Not possible for printers, mutex locks, so this condition usually cannot be removed.
- Hold and wait: a process must request all its resources before it starts, or may request resources only when it holds none (release everything first). Drawbacks: low resource utilization and possible starvation.
- No preemption: if a process holding resources requests one that cannot be given immediately, all resources it holds are released (preempted) and it restarts later; or take resources from a waiting process. Works for CPU registers and memory, not for printers.
- Circular wait: impose a total ordering on all resource types (number them) and require each process to request resources in increasing order (e.g. tape = 1, disk = 5, printer = 12). Then a cycle of waiting processes cannot form. This is the most practical method.
Other approaches: deadlock avoidance (Banker’s algorithm, safe states), detection and recovery, or ignoring the problem.
Q5 – Files and access methods
File: a named collection of related information recorded on secondary storage; the smallest unit of logical storage from the user’s view. It has attributes (name, identifier, type, location, size, protection, timestamps) and operations (create, write, read, reposition/seek, delete, truncate).
Access methods:
- Sequential access: information is processed in order, one record after another; read_next / write_next move a file pointer forward, and reset goes to the beginning. Based on the tape model. Used by editors and compilers.
- Direct (relative) access: the file is a numbered sequence of fixed-length logical records/blocks that can be read or written in any order (read n, write n) – based on the disk model; used for databases and reservation systems where immediate access to large amounts of data is needed.
- Indexed (other) access methods: an index contains pointers to blocks; to find a record, first search the index (e.g. by key) and then access the file directly. For large files, a multi-level index can be used (e.g. IBM ISAM – indexed sequential access).
Q6 – CPU scheduling
FCFS:
| P1 | P2 | P3 | P4 |P5| P6 |
0 15 18 25 30 31 33
SJF (non-preemptive):
|P5| P6 | P2 | P4 | P3 | P1 |
0 1 3 6 11 18 33
Round Robin (q = 2):
| P1 | P2 | P3 | P4 |P5| P6 | P1 |P2| P3 | P4 | P1 | P3 |P4| P1 |P3| P1 | P1 | P1 |P1|
0 2 4 6 8 9 11 13 14 16 18 20 22 23 25 26 28 30 32 33
Priority (non-preemptive, low number = high priority):
| P4 | P1 | P3 |P5| P6 | P2 |
0 5 20 27 28 30 33All processes arrive at 0, so turnaround time = completion time and waiting time = turnaround − burst.
| Waiting time | FCFS | SJF | RR (q=2) | Priority |
|---|---|---|---|---|
| P1 | 0 | 18 | 18 | 5 |
| P2 | 15 | 3 | 11 | 30 |
| P3 | 18 | 11 | 19 | 20 |
| P4 | 25 | 6 | 18 | 0 |
| P5 | 30 | 0 | 8 | 27 |
| P6 | 31 | 1 | 9 | 28 |
| Average | 119/6 = 19.83 | 39/6 = 6.5 | 83/6 = 13.83 | 110/6 = 18.33 |
| Turnaround time | FCFS | SJF | RR (q=2) | Priority |
|---|---|---|---|---|
| P1 | 15 | 33 | 33 | 20 |
| P2 | 18 | 6 | 14 | 33 |
| P3 | 25 | 18 | 26 | 27 |
| P4 | 30 | 11 | 23 | 5 |
| P5 | 31 | 1 | 9 | 28 |
| P6 | 33 | 3 | 11 | 30 |
| Average | 152/6 = 25.33 | 72/6 = 12.0 | 116/6 = 19.33 | 143/6 = 23.83 |
For the priority tie (P3, P5, P6 all priority 5), FCFS order is used. SJF gives the smallest average waiting and turnaround times.
Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.

