Advanced Operating System, Past Papers, UOS Main Campus

Advance Operating System Past Paper 2014 (Session 2013-15) – MS CS 1st Term UOS (CS-5641)

ProgramMS CS
Term1st
Year2013
Course codeCS-5641
AnswersSolved ✓

University of Sargodha MS Computer Science 1st term Advance Operating System (CS-5641) paper, 2014 exam, session 2013-15 (80 marks, 3 hours). The paper has been retyped, and solved answers are given below for all short questions and all six long questions, including dual-mode operation, multilevel feedback queues, inverted page tables, page-replacement ranking and the Banker’s algorithm.

Solved answers

Q1 – Short answers (8 × 2)

I. Process: A program in execution, together with its current activity: program counter, registers, stack, data section and heap. It is the unit of work in an OS and is represented by a Process Control Block (PCB).

II. Thread: A lightweight process – the basic unit of CPU utilisation inside a process, with its own thread ID, program counter, registers and stack but sharing code, data and open files with other threads of the same process.

III. Race condition: A situation where several processes/threads access and change shared data concurrently and the final result depends on the order of execution, e.g. two threads doing counter++ at the same time can lose an update.

IV. Mutual exclusion: The requirement that when one process is executing in its critical section (using a shared resource), no other process may execute in its critical section for that resource. Achieved with locks, semaphores or monitors.

V. Semaphore and its use: An integer variable accessed only through atomic operations wait() (P) and signal() (V). Used for mutual exclusion (binary semaphore/mutex) and for synchronisation or counting resources (counting semaphore), e.g. in producer-consumer problems.

VI. Demand paging: Pages are loaded into memory only when they are referenced (lazy loading). A reference to a page not in memory causes a page fault, and the OS brings that page from disk. This saves memory and allows programs larger than physical memory.

VII. Bootstrap program: A small program stored in ROM/firmware (BIOS/UEFI) that runs when the computer is powered on; it initialises the hardware, then locates and loads the OS kernel into memory and starts it.

VIII. Role of interrupt handlers in device management: When a device finishes an operation or needs attention it raises an interrupt; the CPU saves its state and runs the interrupt handler (ISR), which services the device (e.g. moves data, records status), wakes the waiting process and returns, so the CPU does not have to poll devices.

Q2 – Dual mode, system calls, device controllers

a) Two modes of operation: a mode bit in hardware distinguishes kernel (supervisor) mode from user mode. Privileged instructions – I/O, changing the timer, managing interrupts and memory protection – can execute only in kernel mode. This protects the OS and other users from faulty or malicious programs: a user program that tries a privileged instruction causes a trap to the OS. Control passes to kernel mode only through system calls, interrupts and exceptions.

b) System call: the programming interface through which a user program requests a service from the OS kernel. It is needed because user programs cannot directly access hardware or kernel data; the system call switches to kernel mode in a controlled way, performs the operation and returns. Example: read(fd, buf, n) in UNIX (or ReadFile() in Windows) to read from a file; others are fork(), open(), write(), exit().

c) Functionality in the device controller instead of the kernel (Silberschatz):

  • Advantages: (1) bugs in that code are less likely to crash the OS; (2) performance can improve because dedicated hardware/firmware and algorithms run on the controller, freeing the CPU; (3) the kernel becomes simpler because the algorithm is moved out of it.
  • Disadvantages: (1) bugs are harder to fix – a firmware update is needed instead of a new kernel; (2) improving the algorithms requires a hardware upgrade rather than a software update; (3) embedded algorithms may conflict with the application’s needs or the OS’s policies and reduce flexibility (e.g. the OS cannot see or change the controller’s scheduling).

Q3 – Multiple queues and fragmentation

a) Multiple queues: processes have different needs (interactive vs batch, short vs long), so one queue and one policy cannot serve all well. Multilevel queue scheduling partitions the ready queue into several permanent queues (e.g. system, interactive, batch), each with its own algorithm (RR for foreground, FCFS for background); scheduling between queues uses fixed priority or time slicing (e.g. 80% foreground, 20% background). A process stays in its queue, so low-priority queues may starve.

Multilevel feedback queue allows processes to move between queues: a new process enters queue 0 (quantum 8 ms); if it does not finish, it moves down to queue 1 (quantum 16 ms), then to queue 2 (FCFS). CPU-bound processes sink to lower queues, interactive and I/O-bound processes stay high, and aging moves a long-waiting process up to prevent starvation. It is defined by the number of queues, the algorithm per queue, and rules for upgrading/demoting processes.

b) The wasted space inside the last block is internal fragmentation (space allocated but not used). Analogy: it is like paging in memory management, where the last page of a process is partly empty; contiguous allocation of files also causes external fragmentation (free space broken into small holes between files), just like contiguous memory allocation, which needs compaction (defragmentation). Linked and indexed allocation remove external fragmentation, but internal fragmentation in the last block remains for any fixed block size.

Q4 – Deadlock, two-phase locking, livelock, starvation; inverted page table

a) Deadlock: a set of processes is deadlocked when each holds some resource and waits 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. Necessary conditions: mutual exclusion, hold and wait, no preemption, circular wait.

  • Two-phase locking (2PL): a concurrency-control protocol in which each transaction has a growing phase (it may obtain locks but not release any) followed by a shrinking phase (it may release locks but not obtain any). It guarantees conflict-serialisability but does not prevent deadlock – e.g. T1 locks A then requests B while T2 locks B then requests A.
  • Livelock: processes are not blocked but keep changing state in response to each other without making progress, e.g. two processes repeatedly back off and retry at the same moment (like two people in a corridor stepping aside in the same direction).
  • Starvation: a process waits indefinitely because others are always favoured, e.g. a low-priority process under priority scheduling, or a writer that never gets the lock in a readers-preferred readers-writers solution. Solved by aging.

Difference: in deadlock processes are blocked forever in a cycle; in livelock they are active but make no progress; in starvation the system makes progress but one process is postponed indefinitely.

b) Inverted page table: instead of one page table per process, the system keeps one table with one entry per physical frame; each entry holds <process-id, page-number> of the page stored in that frame. A logical address <pid, p, d> is translated by searching the table for the entry matching (pid, p); if it is found at index i, the physical address is <i, d> (frame i, offset d); otherwise a page fault occurs. This saves memory (table size depends on physical memory), but searching is slow, so a hash table (and TLB) is used, and shared memory is harder to implement.

Q5 – Failures in distributed systems; interrupt vs polling

a) (i) Types of failure: (1) link (communication line) failure, (2) site/node failure (crash of a computer), (3) loss of messages (or messages corrupted/duplicated/delayed). Others: network partition, Byzantine (arbitrary) failures.

(ii) Site failure (a crash of the machine or a process) and message/data loss within the machine’s buses or disks apply to a centralized system as well; link failure and network partition apply only to distributed systems.

b) A single serial port is slow and data arrives rarely and unpredictably, so polling it would waste many CPU cycles; interrupt-driven I/O lets the CPU do other work and respond only when a character arrives. A front-end processor (terminal concentrator) receives a continuous, high volume of input from many terminals; with interrupts the overhead of an interrupt per character would be huge, while polling in a tight loop finds data almost every time it checks, so polling is more efficient there.

Q6 – Ranking page-replacement algorithms

Rank (1 bad – 5 perfect)AlgorithmBelady’s anomaly?
1 – BadFIFOSuffers
3 – AverageSecond-chance (clock)Suffers (it degenerates to FIFO when all reference bits are set)
4 – GoodLRUDoes not suffer (stack algorithm)
5 – PerfectOptimal (OPT/MIN)Does not suffer (stack algorithm)

Optimal gives the lowest possible fault rate but needs future knowledge; LRU approximates it well; second-chance approximates LRU cheaply; FIFO ignores usage. Example of Belady’s anomaly with FIFO: reference string 1,2,3,4,1,2,5,1,2,3,4,5 gives 9 faults with 3 frames but 10 faults with 4 frames.

Q7 – Banker’s algorithm; segmentation vs paging

a) Banker’s algorithm (Dijkstra) is a deadlock-avoidance algorithm for multiple instances of each resource type. Each process declares its maximum need in advance. Data structures for n processes and m resource types: Available[m], Max[n][m], Allocation[n][m], Need = Max − Allocation.

Safety algorithm:
1. Work = Available; Finish[i] = false for all i
2. Find i with Finish[i] == false and Need[i] <= Work; if none go to 4
3. Work = Work + Allocation[i]; Finish[i] = true; go to 2
4. If Finish[i] == true for all i, the state is SAFE

Resource-request algorithm for Pi with Request[i]:
1. If Request[i] > Need[i] -> error (exceeded maximum claim)
2. If Request[i] > Available -> Pi must wait
3. Pretend to allocate: Available -= Request; Allocation[i] += Request; Need[i] -= Request
4. Run safety algorithm: if safe, grant; otherwise restore old state and Pi waits

Example: with Available = (3,3,2) and five processes in the textbook example, the sequence <P1, P3, P4, P2, P0> satisfies the safety criteria, so the state is safe. The algorithm never enters an unsafe state, so deadlock cannot occur, but it requires known maximum needs and a fixed number of processes/resources.

b) Segmentation vs paging:

PagingSegmentation
Divides memory into fixed-size pages/framesDivides program into variable-size logical segments (code, stack, data, functions)
Invisible to programmer (physical view)Visible to programmer (logical view)
No external fragmentation; small internal fragmentation in last pageNo internal fragmentation; suffers external fragmentation
Address = page number + offset; page tableAddress = segment number + offset; segment table with base and limit
Sharing and protection per pageNatural sharing and protection per segment (e.g. read-only code)

Applications: paging is used by all modern OSs for virtual memory (Linux, Windows); segmentation is used for logical protection and sharing (Intel x86 segments, Multics) and is often combined with paging (segmented paging) to get the benefits of both.

Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.