2 Process Management

Operating Systems ยท Unit 2 ยท 10 hrs

Process Management

Exam-focused notes for Process Management (Operating Systems, CSC264): what the TU syllabus asks and how it has actually been tested, with 19 solved past questions from this unit.

Process Management in short

This chapter studies the process as the operating system's central unit of execution: how a process differs from the program it runs, how the operating system tracks and switches between processes and threads, how independent processes coordinate access to shared data without racing each other, and how the scheduler decides which runnable process gets the CPU next.

Process Management: notes

Process vs Program

A program is a passive, static entity: a set of instructions stored on disk, occupying a single place until deleted. A process is the corresponding dynamic entity, an instance of a program in execution together with its current values of the program counter, registers and variables. A process actively requires resources such as CPU time, memory and open file handles for the duration of its lifetime, and it is tracked internally by its own process control block, whereas a program has no such requirement or control block and exists in storage regardless of whether it is running.

ProcessProgram
A dynamic, executing activityA static set of instructions on disk
Requires CPU, memory, and other resources while it runsRequires only storage space
Has a process control blockHas no control block
Exists only for the limited time it takes to complete its taskContinues to exist until explicitly deleted

Multiprogramming

In a multiprogramming system, the CPU switches rapidly between several processes, running each for tens or hundreds of milliseconds at a time, so that from a human timescale all of them appear to progress in parallel even though only one instruction stream is actually executing at any instant. This rapid switching is what lets the CPU stay busy with a second process's computation while a first process is blocked waiting for I/O, and it is why operating system designers model concurrent activity as a set of sequential processes rather than trying to reason about the raw interleaving of instructions directly.

Process Model

Under the process model, all the runnable software on a computer, including parts of the operating system itself, is organized as a number of conceptually independent sequential processes, each with its own logical program counter, registers and variables, even though the machine has only one physical program counter. When the scheduler switches to a process, that process's saved logical program counter is loaded into the real program counter; when the process is suspended again, the real program counter's value is saved back into that process's own record. Viewed over a long interval, every process makes progress, but at any single instant only one process is actually running, an illusion of parallelism built entirely from fast switching.

Process States

A process moves between a small set of states over its lifetime.

  • New: the process is being created.
  • Ready: the process is waiting to be assigned to a processor.
  • Running: the process's instructions are actually being executed.
  • Waiting (blocked): the process is waiting for an event, such as I/O completion, before it can continue.
  • Terminated: the process has finished execution.

A process created (new) is admitted into the ready queue; the scheduler dispatches a ready process to running; a running process may be preempted back to ready, may block waiting for an event and move to waiting, or may finish and move to terminated; a waiting process returns to ready once its event occurs. A shell pipeline such as cat file1 file2 file3 | grep tree illustrates why waiting exists: depending on the relative speed of the two processes, grep may be ready to run before cat has produced any input for it, in which case grep must block until input becomes available rather than busily consuming CPU time for nothing.

Process Control Block

To implement the process model the operating system maintains an array of structures called the process table, with one entry, or process control block (PCB), per process. Each PCB typically records the process's current state, its process ID (PID), its saved program counter, its CPU register contents, memory management information such as base and limit registers or a page table pointer, I/O status information including open files and pending requests, and scheduling information such as priority and pointers into scheduling queues. The PCB is what makes a context switch possible: when the operating system suspends a running process, it saves the CPU state into that process's PCB, and when it later resumes the process it reloads exactly that saved state from the PCB.

Threads

A thread is a path of execution within a process; a single process can contain multiple threads, each representing an independent flow of control while all of them share the same address space, open files and other process-wide resources. Threads are sometimes called lightweight processes (LWPs) because creating and switching between them costs far less than creating and switching between full processes. By letting parts of an application run concurrently on shared memory, threads improve performance in workloads such as network and web servers, where one thread can continue serving other clients while another thread blocks on I/O.

Thread vs Process

ProcessThread
Heavyweight, resource intensiveLightweight, needs fewer resources
Switching requires operating system involvementSwitching does not need OS involvement
Each process has its own memory and file resourcesAll threads of a process share the same open files and memory
If one process blocks, no other process is affectedIf one thread blocks, another thread in the same process can still run
Independent of other processesOne thread can read, write or otherwise affect another thread's data

User and Kernel Space Threads

Threads can be implemented at two different levels.

User level threads are managed entirely by a thread library linked into the application; the kernel is not aware that more than one thread exists inside a process. The library handles thread creation, destruction, scheduling and context saving on its own.

  • Advantages: switching does not require kernel mode privileges, so it is fast; scheduling can be customized per application; user level threads can run on any operating system with the library available; they are quick to create and destroy.
  • Disadvantages: because most system calls block at the kernel level, one blocking system call stops the whole process, not just the calling thread; a user-threaded application also cannot exploit multiple processors, since the kernel only ever sees one schedulable entity.

Kernel level threads are created, scheduled and destroyed directly by the operating system, with no thread management code in the application itself.

  • Advantages: the kernel can schedule several threads of the same process on different processors simultaneously; if one thread blocks, the kernel simply schedules another thread of the same process; kernel routines themselves can be multithreaded.
  • Disadvantages: creating and managing kernel threads is slower than user threads, since every operation requires a kernel mode switch; transferring control between threads of the same process still needs a mode switch to the kernel.

Inter Process Communication

Inter-process communication (IPC) is the set of mechanisms that let processes exchange data and synchronize their actions, for example so that one process can notify another that an event has occurred, or so that data can be transferred from one process to another. IPC design has to resolve three related concerns: how information is passed from one process to another, how two or more processes are kept from interfering with each other while using shared resources (mutual exclusion), and how correct ordering is maintained when one process's work depends on another's.

What this unit covers

  • Process vs Program
  • Multiprogramming
  • Process Model
  • Process States
  • Process Control Block
  • Threads
  • Thread vs Process
  • User and Kernel Space Threads
  • Inter Process Communication
  • Race Condition
  • Critical Section
  • Implementing Mutual Exclusion: Mutual Exclusion with Busy Waiting (Disabling Interrupts, Lock Variables, Strict Alteration, Peterson's Solution, Test and Set Lock)
  • Sleep and Wakeup
  • Semaphore
  • Monitors
  • Message Passing
  • Classical IPC problems: Producer Consumer, Sleeping Barber, Dining Philosopher Problem
  • Process Scheduling: Goals, Batch System Scheduling (First-Come First-Served, Shortest Job First, Shortest Remaining Time Next), Interactive System Scheduling (Round-Robin Scheduling, Priority Scheduling, Multiple Queues), Overview of Real Time System Scheduling

Classical IPC problems

2081 ยท 10 marks

Explain the Sleeping Barber problem. Illustrate on how it can be solved.[10]

The Sleeping Barber Problem is a classic Inter-Process Communication (IPC) and process synchronization problem introduced by Dijkstra. It models a real-world scenario involving a barber shop and illustrates the challenges of coordinating multiple concurrent processes. - A barber shop has one barb...

Open this answer on its own page โ†’

Semaphore

2081 ยท 5 marks

Explain how semaphore solves the problem of critical section. [5]

A critical section is the part of a program where shared memory or shared resources are accessed. When multiple processes/threads enter their critical sections simultaneously, a race condition occurs, producing incorrect or unpredictable results depending on execution order. A correct solution to...

Open this answer on its own page โ†’

Process Scheduling

2081 ยท 5 marks

Calculate the average waiting time and turnaround time using priority algorithm (Priority 1 being the highest) for the given scenario:

$$\begin{array}{|c|c|c|c|} \hline \text{PID} & \text{Burst Time} & \text{Arrival Time} & \text{Priority} \ \hline A & 3 & 0 & 3 \ B & 2 & 2 & 3 \ C & 4 & 3 & 2 \ D & 2 & 3 & 1 \ \hline \end{array}$$

[5]

Show solved answer

Priority Scheduling (Non-Preemptive) - Average WT and TAT

Given

PIDBurst TimeArrival TimePriority
A303
B223
C432
D231

Priority 1 = highest. Assume non-preemptive priority scheduling.


Solution

Execution Order

  • t = 0: Only A available โ†’ A runs 0 to 3.
  • t = 3: Ready = B (P3), C (P2), D (P1). Highest priority = D โ†’ D runs 3 to 5.
  • t = 5: Ready = B (P3), C (P2). Higher priority = C โ†’ C runs 5 to 9.
  • t = 9: Only B remains โ†’ B runs 9 to 11.

Gantt Chart

| A | D |  C  | B |
0   3   5     9  11

Completion, Turnaround, Waiting Times

TAT = CT โˆ’ AT, WT = TAT โˆ’ BT

PIDATBTCTTAT = CTโˆ’ATWT = TATโˆ’BT
A03330
B221197
C34962
D32520

Averages

$$\text{Avg TAT} = \frac{3 + 9 + 6 + 2}{4} = \frac{20}{4} = 5 \text{ ms}$$

$$\text{Avg WT} = \frac{0 + 7 + 2 + 0}{4} = \frac{9}{4} = 2.25 \text{ ms}$$


Final Result

MetricValue
Average Turnaround Time5 ms
Average Waiting Time2.25 ms
Open this answer on its own page โ†’

2080 ยท 10 marks

(question text pending review) # Answer

When does the request switch from user mode to kernel mode?

A request switches from user mode to kernel mode through a system call (also calle

Show solved answer

User Mode to Kernel Mode Switch + Process Scheduling

Given Data

ProcessArrival Time (AT)Burst Time (BT)Priority
P0051 (Lowest)
P1134 (Highest)
P2282
P3363

Priority convention (from question): higher number = higher priority (P1 = 4 = Highest).


Part 1: User Mode to Kernel Mode Switch

A CPU runs in two modes controlled by a mode bit:

  • User Mode (bit = 1): application programs run with restricted privileges.
  • Kernel Mode (bit = 0): the OS runs with full hardware access.

The switch from user mode to kernel mode occurs whenever a user process needs a privileged operation it cannot perform itself. This is triggered by:

TriggerDescription
System CallProcess requests an OS service (file I/O, memory allocation)
Hardware InterruptExternal device signals CPU (keyboard, disk, timer)
Trap / ExceptionError condition (division by zero, page fault, invalid access)

Mechanism: user process issues a system-call/trap instruction โ†’ CPU saves user state โ†’ mode bit set to 0 (kernel) โ†’ OS runs the system-call handler โ†’ on completion, mode bit set to 1 (user) โ†’ control returns to the process.

Example:

int fd = open("file.txt", O_RDONLY);   // system call

The open() call traps into the kernel. The CPU switches to kernel mode, the kernel checks permissions and locates the file, returns a file descriptor, then switches back to user mode. The process cannot touch the disk directly, so it must request the kernel to act on its behalf.


Part 2: Process Scheduling

Algorithm 1: FCFS (Non-preemptive, by arrival order)

Order: P0 โ†’ P1 โ†’ P2 โ†’ P3

Gantt Chart

| P0 | P1 |   P2    |    P3     |
0    5    8         16          22
ProcessATBTCTTAT = CT-ATWT = TAT-BT
P005550
P113874
P22816146
P336221913

$$\text{Avg TAT} = \frac{5+7+14+19}{4} = \frac{45}{4} = 11.25 \text{ ms}$$ $$\text{Avg WT} = \frac{0+4+6+13}{4} = \frac{23}{4} = 5.75 \text{ ms}$$


Algorithm 2: Priority Scheduling (Non-preemptive, higher number = higher priority)

  • t=0: only P0 arrived โ†’ run P0 (until t=5).
  • t=5: P1(4), P2(2), P3(3) available โ†’ highest is P1 (until t=8).
  • t=8: P2(2), P3(3) โ†’ highest is P3 (until t=14).
  • t=14: only P2 โ†’ run (until t=22).

Gantt Chart

| P0 | P1 |   P3    |    P2     |
0    5    8         14          22
ProcessATBTCTTAT = CT-ATWT = TAT-BT
P005550
P113874
P33614115
P228222012

$$\text{Avg TAT} = \frac{5+7+11+20}{4} = \frac{43}{4} = 10.75 \text{ ms}$$ $$\text{Avg WT} = \frac{0+4+5+12}{4} = \frac{21}{4} = 5.25 \text{ ms}$$


Algorithm 3: Round Robin (Quantum = 2, preemptive)

BTs: P0=5, P1=3, P2=8, P3=6. Ready-queue ordering by arrival; a preempted process rejoins the tail after newly arrived processes.

Trace the ready queue (arrivals: P0@0, P1@1, P2@2, P3@3):

TimeRunRemaining afterQueue state after
0-2P03P1 arrived@1, P2@2 present; queue: P1,P2,P0 (P3@3 next)
2-4P11during run P3@3 arrives โ†’ queue: P2,P0,P3,P1
4-6P26queue: P0,P3,P1,P2
6-8P01queue: P3,P1,P2,P0
8-10P34queue: P1,P2,P0,P3
10-11P10 โ†’ CT=11queue: P2,P0,P3
11-13P24queue: P0,P3,P2
13-14P00 โ†’ CT=14queue: P3,P2
14-16P32queue: P2,P3
16-18P22queue: P3,P2
18-20P30 โ†’ CT=20queue: P2
20-22P20 โ†’ CT=22empty

Gantt Chart

|P0|P1|P2|P0|P3|P1|P2|P0|P3|P2|P3|P2|
0  2  4  6  8 10 11 13 14 16 18 20 22
ProcessATBTCTTAT = CT-ATWT = TAT-BT
P00514149
P11311107
P228222012
P336201711

$$\text{Avg TAT} = \frac{14+10+20+17}{4} = \frac{61}{4} = 15.25 \text{ ms}$$ $$\text{Avg WT} = \frac{9+7+12+11}{4} = \frac{39}{4} = 9.75 \text{ ms}$$


Summary

AlgorithmAvg Waiting TimeAvg Turnaround Time
FCFS5.75 ms11.25 ms
Priority (non-preemptive)5.25 ms10.75 ms
Round Robin (Q=2)9.75 ms15.25 ms
Open this answer on its own page โ†’

2079 ยท 5 marks

For the following dataset, compute average waiting time for SRTN and SJF.

ProcessArrival TimeBurst Time
P007
P124
P241
P354

[5]

Show solved answer

SRTN and SJF Scheduling - Average Waiting Time

Given

ProcessArrival TimeBurst Time
P007
P124
P241
P354

All required data present.


Solution

Part 1: SRTN (Shortest Remaining Time Next) - Preemptive

At each new arrival, compare remaining times and run the smallest.

Execution Trace

  • t=0: Only P0. Run P0.
  • t=2: P1 arrives (4). P0 remaining = 5. Since 4 < 5, run P1. (P0 rem = 5)
  • t=4: P2 arrives (1). P1 remaining = 2. Since 1 < 2, run P2. (P0=5, P1=2)
  • t=5: P2 finishes. P3 arrives (4). Ready: P1=2, P3=4, P0=5. Run P1.
  • t=7: P1 finishes. Ready: P3=4, P0=5. Run P3.
  • t=11: P3 finishes. Run P0 (5 remaining).
  • t=16: P0 finishes.

Note: at $t=4$ the remaining time for P1 is $4 - 2 = \mathbf{2}$ units, since P1 ran from $t=2$ to $t=4$.

Gantt Chart

| P0 | P1 | P2 | P1 | P3 | P0  |
0    2    4    5    7   11   16

Waiting Time (WT = Completion - Arrival - Burst)

ProcessCompletionArrivalBurstWaiting Time
P0160716 - 0 - 7 = 9
P17247 - 2 - 4 = 1
P25415 - 4 - 1 = 0
P3115411 - 5 - 4 = 2

$$\text{Average WT (SRTN)} = \frac{9 + 1 + 0 + 2}{4} = \frac{12}{4} = \boxed{3.0 \text{ ms}}$$


Part 2: SJF (Shortest Job First) - Non-Preemptive

  • t=0: Only P0 arrived. Run P0 to completion โ†’ finishes at 7.
  • t=7: P1(4), P2(1), P3(4) all arrived. Shortest = P2. Run P2 โ†’ finishes at 8.
  • t=8: P1(4), P3(4). Tie broken by arrival โ†’ P1. Finishes at 12.
  • t=12: P3 runs โ†’ finishes at 16.

Gantt Chart

| P0      | P2 | P1     | P3     |
0         7    8       12      16

Waiting Time

ProcessCompletionArrivalBurstWaiting Time
P07070
P112246
P28413
P316547

$$\text{Average WT (SJF)} = \frac{0 + 6 + 3 + 7}{4} = \frac{16}{4} = \boxed{4.0 \text{ ms}}$$


Summary

AlgorithmAverage Waiting Time
SRTN (Preemptive)3.0 ms
SJF (Non-Preemptive)4.0 ms
Open this answer on its own page โ†’

2078 ยท 5 marks

Discuss the concept of SJF and SRTN scheduling algorithms with suitable example. [5]

SJF is a non-preemptive CPU scheduling algorithm in which the process with the smallest burst time (CPU time) is selected next for execution from the ready queue. Once a process starts executing, it runs to completion without interruption. - Non-preemptive in nature - Minimizes average waiting ti...

Open this answer on its own page โ†’

2076 ยท 10 marks

Interactive System Goals and Scheduling Algorithms

Interactive systems serve users who expect fast, predictable responses. Scheduling goals: - Response Time: Minimize time from request to first response. - Proportionality: Simple tasks should feel quick; user expectations must be met. - Fairness: Every process gets a fair CPU share; no starvation...

Open this answer on its own page โ†’

2080.1 ยท 10 marks

Why do we need to schedule process? Find the average waiting time and average turnaround time for the following set of processes using FCFS, SJF, RR (Quantum = 3) and shortest remaining time next.

ProcessCPU burst timeArrival time
P1200
P22515
P31030
P41545

[10]

Show solved answer

Process Scheduling Solution

Given Data

ProcessBurst TimeArrival Time
P1200
P22515
P31030
P41545

Quantum for RR = 3

Formulas:

  • $TAT = CT - AT$
  • $WT = TAT - BT$

Why Do We Need to Schedule Processes?

  • CPU utilization: keep the CPU busy in a multiprogramming environment.
  • Throughput: maximize processes completed per unit time.
  • Fairness: give each process a reasonable share of CPU.
  • Minimize waiting, turnaround, and response times.
  • Prevent starvation and manage resources efficiently.

1. FCFS

Execution order by arrival: P1, P2, P3, P4.

Gantt: |P1|P2|P3|P4| at 0-20-45-55-70

ProcessATBTCTTATWT
P102020200
P2152545305
P33010552515
P44515702510

$$AWT = \frac{0+5+15+10}{4} = 7.5\text{ ms}$$ $$ATAT = \frac{20+30+25+25}{4} = 25\text{ ms}$$


2. SJF (Non-Preemptive)

  • t=0: only P1 arrived โ†’ run P1 (0-20).
  • t=20: only P2 arrived โ†’ run P2 (20-45).
  • t=45: P3 (BT=10) and P4 (BT=15) available โ†’ pick P3 (45-55).
  • t=55: run P4 (55-70).

Same schedule as FCFS.

$$AWT = 7.5\text{ ms},\quad ATAT = 25\text{ ms}$$


3. Round Robin (Quantum = 3)

Ready queue rule: on preemption, newly arrived processes are inserted before the preempted process.

Trace:

  • 0-3: P1 (17). Queue: [P1]
  • 3-6: P1 (14). Queue: [P1]
  • 6-9: P1 (11). Queue: [P1]
  • 9-12: P1 (8). Queue: [P1]
  • 12-15: P1 (5). At t=15 P2 arrives. Queue after: [P2, P1]
  • 15-18: P2 (22). Queue: [P1, P2]
  • 18-21: P1 (2). Queue: [P2, P1]
  • 21-24: P2 (19). Queue: [P1, P2]
  • 24-27: P1 (2โ†’0, runs 2 ms, done at 26).

To be precise. At 24-27 P1 has only 2 ms remaining, so:

  • 24-26: P1 (2โ†’0, P1 completes at 26). Queue: [P2]. At t=30 P3 arrives later.
  • 26-29: P2 (16). Queue: [P2]
  • 29-32: P2 (13). P3 arrives at t=30. Queue after: [P3, P2]
  • 32-35: P3 (7). Queue: [P2, P3]
  • 35-38: P2 (10). Queue: [P3, P2]
  • 38-41: P3 (4). Queue: [P2, P3]
  • 41-44: P2 (7). Queue: [P3, P2]
  • 44-47: P3 (1). P4 arrives at t=45. Queue after: [P2, P4, P3]
  • 47-50: P2 (4). Queue: [P4, P3, P2]
  • 50-53: P4 (12). Queue: [P3, P2, P4]
  • 53-54: P3 (1โ†’0, P3 completes at 54). Queue: [P2, P4]
  • 54-57: P2 (1). Queue: [P4, P2]
  • 57-60: P4 (9). Queue: [P2, P4]
  • 60-61: P2 (1โ†’0, P2 completes at 61). Queue: [P4]
  • 61-64: P4 (6). Queue: [P4]
  • 64-67: P4 (3). Queue: [P4]
  • 67-70: P4 (3โ†’0, P4 completes at 70).

Completion times: P1=26, P2=61, P3=54, P4=70

ProcessATBTCTTATWT
P102026266
P21525614621
P33010542414
P44515702510

$$AWT = \frac{6+21+14+10}{4} = \frac{51}{4} = 12.75\text{ ms}$$ $$ATAT = \frac{26+46+24+25}{4} = \frac{121}{4} = 30.25\text{ ms}$$

(Note: RR ordering conventions vary; results depend on insertion order.)


4. Shortest Remaining Time Next (SRTN, Preemptive SJF)

Preempt whenever a newly arrived process has less remaining time.

  • 0-15: P1 runs (only process). At t=15 P1 remaining = 5, P2 arrives (25). P1(5) < P2(25) โ†’ continue P1.
  • 15-20: P1 (5โ†’0, P1 completes at 20).
  • 20-30: P2 runs. At t=30 P2 remaining = 15, P3 arrives (10). P3(10) < P2(15) โ†’ preempt.
  • 30-40: P3 (10โ†’0, P3 completes at 40).
  • 40-45: P2 runs (15โ†’10). At t=45 P4 arrives (15). P2(10) < P4(15) โ†’ continue P2.
  • 45-55: P2 (10โ†’0, P2 completes at 55).
  • 55-70: P4 (15โ†’0, P4 completes at 70).

Completion times: P1=20, P2=55, P3=40, P4=70

ProcessATBTCTTATWT
P102020200
P21525554015
P3301040100
P44515702510

$$AWT = \frac{0+15+0+10}{4} = \frac{25}{4} = 6.25\text{ ms}$$ $$ATAT = \frac{20+40+10+25}{4} = \frac{95}{4} = 23.75\text{ ms}$$


Summary

AlgorithmAvg WT (ms)Avg TAT (ms)
FCFS7.525
SJF7.525
RR (q=3)12.7530.25
SRTN6.2523.75
Open this answer on its own page โ†’

Critical Section

2080 ยท 10 marks

How do you recognize critical section? Why do we need to synchronise it? Consider the request for the page references 7,0,1,2,0,3,0,4,2,3,0,3,2. Find the number of page fault for FIFO and LRU with 4 page frames.[10]

--- A critical section is the segment of code in a process where it accesses and manipulates shared resources (shared variables, memory, files, buffers, etc.) that must not be accessed by more than one process simultaneously. How to recognize it: - It reads or writes shared data used by other pro...

Open this answer on its own page โ†’

Implementing Mutual Exclusion

2080 ยท 5 marks

How can we achieve mutual exclusion? Describe. [5]

Mutual exclusion ensures that when one process is executing in its critical region (accessing shared memory/resources), no other process is allowed to enter its critical region at the same time. --- - On a single-processor system, each process disables all interrupts just after entering its criti...

Open this answer on its own page โ†’

2079 ยท 5 marks

List any two demerits of disabling interrupt to achieve mutual exclusion. Describe about fixed and variable partitioning. [5]

Show solved answer

Answer

Two Demerits of Disabling Interrupts for Mutual Exclusion

According to the notes, the following are two demerits of disabling interrupts to achieve mutual exclusion:

  1. Unsafe to give power to user processes: It is unwise to give user processes the power to turn off interrupts. If a user process disables interrupts and never re-enables them, the entire system could come to a halt. This makes the approach unsuitable for general user-level processes.

  2. Not appropriate for user processes: Disabling interrupts is only a useful technique within the operating system itself. It is not appropriate for user processes because a malfunctioning or malicious process could permanently disable interrupts, causing the system to stop functioning correctly.


Fixed and Variable Partitioning

In a multiprogramming environment, several programs reside in primary memory at the same time and the CPU switches control between them. One way to support multiprogramming is to divide main memory into several partitions, each allocated to a single process. Depending on how and when partitions are created, there are two types:

(i) Fixed Partitioning (Static Partitioning)

  • Memory is divided into several fixed-size partitions before execution begins.
  • Each partition can accommodate only one program at a time.
  • The number of programs residing in memory is bounded by the number of partitions.
  • When a program terminates, its partition is freed for another program waiting in the queue.
  • When a job arrives, it is placed in the input queue for the smallest partition large enough to hold it.

Demerit: Since partitions are fixed in size, any unused space within a partition cannot be used by other jobs and is simply wasted while that job runs. This is known as internal fragmentation.


(ii) Variable Partitioning (Dynamic Partitioning)

  • Partitions are not fixed in advance; they are created dynamically at the time a process is loaded into memory.
  • Each process is allocated exactly as much memory as it requires, so there is no internal fragmentation.
  • As processes finish and leave memory, holes (free blocks) are created at various places in memory.
  • Over time, memory becomes fragmented into many small holes scattered throughout, which is known as external fragmentation.
  • Techniques such as compaction may be used to combine these holes into one large free block.

Demerit: External fragmentation occurs over time, making it difficult to allocate contiguous memory to new processes without compaction.


Comparison Table

FeatureFixed PartitioningVariable Partitioning
Partition sizeFixed at system startupDetermined at load time
Internal fragmentationYesNo
External fragmentationNoYes
FlexibilityLowHigh
ImplementationSimpleMore complex
Open this answer on its own page โ†’

2078 ยท 5 marks

What is lock variable? Discuss its working and problems associated with it in detail. [5]

A lock variable is a single, shared variable used to implement mutual exclusion among competing processes. It is initially set to 0 and acts as a flag to indicate whether any process is currently inside its critical region. - Lock = 0 โ†’ No process is in the critical region (region is free) - Lock...

Open this answer on its own page โ†’

2080.1 ยท 5 marks

How lock variable is used in achieving mutual exclusion? Describe. [5]

A lock variable is a shared variable used to control access to a critical region. It is one of the software-based approaches to achieving mutual exclusion with busy waiting. --- A single shared variable called the lock is maintained, initially set to 0. Lock Value Meaning ------ 0 No process is c...

Open this answer on its own page โ†’

Thread vs Process

2080 ยท 5 marks

What makes thread different with process? Draw the transition diagram between states of a process. [5]

Based on the curriculum notes, the key differences are: Process Thread ------ Process is heavy weight or resource intensive. Thread is light weight, taking lesser resources than a process. Process switching needs interaction with the operating system. Thread switching does not need interaction wi...

Open this answer on its own page โ†’

Race Condition

2079 ยท 10 marks

When does race condition occur in inter process communication? What does busy waiting mean and how it can be handled using sleep and wakeup strategy?[10]

A race condition is a situation that may occur inside a critical section. This happens when the result of multiple thread/process execution in a critical section differs according to the order in which the threads execute. Race conditions occur in IPC when two or more processes share common data ...

Open this answer on its own page โ†’

Sleep and Wakeup

2078 ยท 10 marks

What kind of problem arises with sleep and wakeup mechanism of achieving mutual exclusion? Explain with suitable code snippet.[10]

Sleep and Wakeup is an inter-process communication mechanism used to achieve mutual exclusion and process synchronization. As stated in the notes: "Sleep is a system call that causes the caller to block (i.e., to be suspended) until another process wakes it up. The wakeup call has one parameter, ...

Open this answer on its own page โ†’

User and Kernel Space Threads

2076 ยท 5 marks

When threads are better than processes? Explain the concept of user level threads in detail. [5]

--- Threads are preferred over processes in the following situations: Situation Reason ------ Resource sharing All threads share the same set of open files, child processes, and memory. Processes require separate resources. Speed and lightweight operation Thread is lightweight and takes lesser re...

Open this answer on its own page โ†’

Monitors

2076 ยท 5 marks

What is problem associated with semaphores? Explain the concept of monitors in brief. [5]

Semaphores are a widely used synchronization mechanism, but they suffer from several serious problems: 1. Incorrect Use / Programming Errors: Semaphores require programmers to call wait() (down) and signal() (up) in the correct order. A single mistake can cause serious issues: - If a process forg...

Open this answer on its own page โ†’

Process States

2080.1 ยท 5 marks

What is system call? Describe the transition between different states of process. [5]

--- A system call is the interface between a process (i.e., a user program) and the operating system. When a user program needs to request a service from the operating system (such as reading a file, creating a process, etc.), it does so through system calls. System calls are generally available ...

Open this answer on its own page โ†’