Operating Systems, Past Papers

Operating System MSc IT 2nd Term Past Paper 2018 UOS

Operating System MSc IT 2nd term past paper 2018 University of Sargodha

University of Sargodha M.Sc. IT 2nd term Operating System (CMP-3611) past paper 2018, retyped from the original paper, with solved answers below.

Solved answers

Q1 – Short questions

(1) Context switch: saving the state (registers, program counter, etc. in the PCB) of the running process and loading the saved state of the next process so the CPU can switch between processes. It is pure overhead.

(2) Interrupt vs trap: an interrupt is a hardware-generated, asynchronous signal from a device (e.g. I/O completion, timer). A trap (exception) is a software-generated, synchronous event caused by the running program — an error such as divide by zero or a deliberate system call.

(3) Roll out / roll in: a swapping variant used with priority scheduling: when a higher-priority process arrives, a lower-priority process is swapped out (rolled out) to the backing store, and when the higher-priority process finishes it is swapped back (rolled in).

(4) Stub in dynamic linking: a small piece of code placed in the program for each library routine; when called, it locates the memory-resident library routine (or loads it), replaces itself with the routine’s address and executes it.

(5) Process vs thread: a process is a program in execution with its own address space and resources; a thread is a unit of execution within a process that shares the process’s code, data and files but has its own registers, program counter and stack. Threads are cheaper to create and switch.

(6) Ready queue: the list (usually a linked list of PCBs) of processes residing in main memory that are ready and waiting to execute on the CPU.

(7) Clustered systems: two or more independent computers (nodes) connected by a LAN and sharing storage, working together to provide high availability and/or high performance; can be symmetric or asymmetric (hot-standby).

(8) System call: the programming interface through which a user program requests a service from the operating system kernel, e.g. open(), read(), fork().

(9) Busy-waiting semaphore (spinlock): a semaphore in which a process waiting to enter the critical section loops continuously testing the lock instead of blocking; it wastes CPU cycles but avoids context switches, so it is useful on multiprocessors for short waits.

(10) Compaction: shuffling the contents of memory to place all free memory together in one large block, solving external fragmentation. It requires dynamic relocation at run time.

(11) Entry section vs remainder section: the entry section is the code in which a process requests permission to enter its critical section; the remainder section is the rest of the code after the exit section, which does not access shared data.

(12) Free-space management techniques: bit vector (bitmap), linked list, grouping and counting.

(13) Address binding times: compile time (absolute code), load time (relocatable code) and execution time (binding delayed until run time; needs MMU hardware).

(14) Benefits of virtual memory: programs can be larger than physical memory; more programs run at the same time (higher CPU utilisation); less I/O to load or swap programs; easy sharing of files and memory; efficient process creation.

(15) Deadlock: a state in which a set of processes are all blocked, each holding a resource and waiting for a resource held by another process in the set, so none of them can proceed.

(16) Symmetric vs asymmetric multiprocessing: in SMP all processors are peers; each runs OS and user tasks and shares the scheduler. In asymmetric multiprocessing a master processor controls the system and assigns specific tasks to slave processors.

Q2

a) Monitor: a high-level synchronisation construct (abstract data type) that contains shared variables, the procedures that operate on them and initialisation code. Only one process can be active inside the monitor at a time, so mutual exclusion is automatic.

Structure:

monitor monitor_name
{
    // shared variable declarations
    condition x, y;

    procedure P1 (...) { ... }
    procedure P2 (...) { ... }
    ...
    procedure Pn (...) { ... }

    initialization_code (...) { ... }
}

Processes waiting to enter wait in an entry queue. Condition variables allow waiting inside the monitor: x.wait() suspends the caller until another process calls x.signal(), which resumes exactly one suspended process (no effect if none is waiting).

b) SCAN and C-SCAN disk scheduling:

  • SCAN (elevator algorithm): the disk arm starts at one end and moves towards the other end, servicing requests along the way; at the end it reverses direction and services requests on the way back. Gives more uniform wait than SSTF but requests just behind the head wait long.
  • C-SCAN (circular SCAN): the head moves in one direction servicing requests; when it reaches the end it returns immediately to the beginning without servicing anything on the return trip, treating the cylinders as a circular list. This gives a more uniform waiting time.

Example: queue 98, 183, 37, 122, 14, 124, 65, 67, head at 53, moving toward 0. SCAN: 53 → 37 → 14 → 0 → 65 → 67 → 98 → 122 → 124 → 183 (total head movement 53 + 183 = 236 cylinders).

Q3

a) Process Control Block (PCB): the data structure the OS keeps for every process. Components: process state (new, ready, running, waiting, terminated); process ID; program counter; CPU registers; CPU-scheduling information (priority, queue pointers); memory-management information (base/limit registers, page or segment tables); accounting information (CPU time used, time limits); I/O status information (allocated devices, list of open files).

b) Operating-system services: user interface (CLI, GUI, batch); program execution; I/O operations; file-system manipulation; communication (shared memory or message passing); error detection; and for efficient operation: resource allocation, accounting, and protection and security.

Q4 – Page replacement (3 frames)

Reference string: 4, 3, 2, 1, 5, 1, 2, 3, 2, 3, 4, 5, 5, 5. F marks a page fault.

FIFO — replace the page that came in first: 9 page faults.

Ref43215123234555
Frame 144411111222222
Frame 23335555554444
Frame 3222223333555
FaultFFFFFFFFF

LRU — replace the page not used for the longest time: 8 page faults.

Ref43215123234555
Frame 144411111114444
Frame 23335553333333
Frame 3222222222555
FaultFFFFFFFF

LFU — replace the page with the smallest reference count (ties broken FIFO; a page’s count starts again when it is reloaded): 8 page faults.

Ref43215123234555
Frame 144411111114555
Frame 23335553333333
Frame 3222222222222
FaultFFFFFFFF

Q5

a) System calls provide the interface between a running program and the OS. Categories with Windows and UNIX examples:

CategoryWindowsUNIX
Process controlCreateProcess(), ExitProcess(), WaitForSingleObject()fork(), exit(), wait()
File manipulationCreateFile(), ReadFile(), WriteFile(), CloseHandle()open(), read(), write(), close()
Device manipulationSetConsoleMode(), ReadConsole(), WriteConsole()ioctl(), read(), write()
Information maintenanceGetCurrentProcessID(), SetTimer(), Sleep()getpid(), alarm(), sleep()
CommunicationCreatePipe(), CreateFileMapping(), MapViewOfFile()pipe(), shm_open(), mmap()
ProtectionSetFileSecurity(), InitializeSecurityDescriptor()chmod(), umask(), chown()

b) Operating system: a program that acts as an intermediary between the user and the hardware, manages resources (CPU, memory, devices, files) and provides an environment for executing programs conveniently and efficiently.

Structures: simple/monolithic (MS-DOS, original UNIX — kernel and system programs in one large layer); layered (layer 0 hardware … layer N user interface; each layer uses only lower layers — easy to debug); microkernel (only minimal services in the kernel, others run in user space and communicate by message passing — Mach); modules (core kernel with loadable modules — Linux, Solaris); hybrid systems (Windows, macOS).

+-------------------------------------------+
|        Users / Application programs        |
+-------------------------------------------+
|   Shells, compilers, system programs       |
+-------------------------------------------+
|         System-call interface              |
+-------------------------------------------+
| Kernel: CPU scheduling, memory management, |
| file system, I/O & device drivers          |
+-------------------------------------------+
|   Hardware: CPU, memory, disks, devices    |
+-------------------------------------------+

Q6

a) Dining philosophers problem: five philosophers sit at a round table with a bowl of rice and five chopsticks, one between each pair. A philosopher alternates between thinking and eating, and needs both the left and right chopsticks to eat. Using one semaphore per chopstick (wait(chopstick[i]); wait(chopstick[(i+1)%5]);) can deadlock if all pick up their left chopstick at the same time.

Remedies: allow at most four philosophers at the table; let a philosopher pick up chopsticks only if both are available (inside a critical section/monitor); or use an asymmetric solution — odd philosophers pick left first, even philosophers right first. The monitor solution keeps state[i] ∈ {THINKING, HUNGRY, EATING} and lets philosopher i eat only when neither neighbour is eating.

b) Four necessary conditions: mutual exclusion, hold and wait, no preemption and circular wait — all four must hold simultaneously for deadlock.

Q7 – Resource-allocation graph

Each resource has two instances. Assignments: R1 → P2, P3; R2 → P1, P4; R3 → P2, P3. Requests: P1 → R1, P3 → R2, P4 → R3.

Wait-for graph (Pi → Pj if Pi waits for a resource held by Pj): P1 → P2, P1 → P3; P3 → P1, P3 → P4; P4 → P2, P4 → P3. P2 waits for nothing.

No deadlock. The graph contains cycles (e.g. P1 → P3 → P1), but with multiple instances per resource a cycle is necessary, not sufficient. P2 is not waiting, so it finishes and releases one instance each of R1 and R3. Then P1 gets R1, finishes and releases R2; P3 gets R2 and finishes; P4 gets R3 and finishes. Safe sequence: P2, P1, P3, P4, so all processes complete.

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.