OS END SEM SOLUTIONS NEW - Compressed
OS END SEM SOLUTIONS NEW - Compressed
We are given:
• Scheduling Algorithm: Non-preemptive Shortest Job First (SJF)
• Arrival times: All processes arrive at time = 0 ms
• Burst times:
o P1 = 6
o P2 = ?
o P3 = 2
o P4 = 4
• Average Waiting Time = 5 ms
Let’s denote the unknown burst time of P2 as x.
Step 1: Order processes by burst time (since it's non-preemptive SJF)
Let’s assume the processes execute in ascending order of burst times.
We know:
• P3 = 2
• P4 = 4
• P1 = 6
• P2 = x
So possible execution order depends on x.
To keep this manageable, let’s assume x is an integer and try different values such that the
average waiting time becomes 5 ms.
Step 2: Try different values of x and calculate average waiting time
Let’s try x = 8 (i.e., P2 = 8), and simulate SJF order:
Burst times:
• P3 = 2
• P4 = 4
• P1 = 6
• P2 = 8
Execution order (by SJF):
P3 (2) → P4 (4) → P1 (6) → P2 (8)
Now compute waiting times:
• P3: starts at 0 → WT = 0
• P4: starts at 2 → WT = 2
• P1: starts at 6 → WT = 6
• P2: starts at 12 → WT = 12
Average WT = (0 + 2 + 6 + 12) / 4 = 20 / 4 = 5 ms
Yes, in specific cases, Round Robin (RR) can give the same average waiting time as FCFS.
Example:
● Processes: P1 = 3, P2 = 4, P3 = 2
FCFS:
Proces Start WT
s
P1 0 0
P2 3 3
P3 7 7
→ Race condition occurs, as both processes may enter the critical section.
Process P1:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}
Process P2:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}
→ If 1 thread blocks (e.g., I/O), entire process blocks, so all 3 threads pause.
Processes: P1 = 1, P2 = 10, P3 = 10
Quantum = 4
FCFS:
Waiting times:
● P1: 0
● P2: 1
RR:
Time Process
0-1 P1
(done)
1-5 P2
5-9 P3
9-11 P2
11-13 P3
13-14 P2
14-15 P3
Waiting times:
● P1: 0
● P2: 8
● P3: 8
Given:
● P1 holds A
● P2 holds B
● P3 holds C
Safe guess:
● P1 holds A, requesting B
● P2 holds B, requesting C
● P2 → A
● P3 → B
Graph: P1 → C, P2 → A, P3 → B → no cycle
Example:
P1 holds A, needs B
P2 holds B, needs C
P3 holds C, needs A
But if:
Page reference: 2, 3, 2, 1, 5, 2, 4, 5, 3, 2
Frames = 3
Trace:
● 2 → miss [2]
● 3 → miss [2,3]
● 2 → hit
● 1 → miss [2,3,1]
● 5 → replace 2 → [5,3,1]
● 2 → replace 3 → [5,2,1]
● 4 → replace 1 → [5,2,4]
● 5 → hit
● 3 → replace 2 → [5,3,4]
● 2 → replace 4 → [5,3,2]
Replaced twice:
● re-added at 6th
Example:
● Hard link: Points to inode. File persists until all hard links are deleted
Segment 1:
● base = 500
• Those who have taken right end of this 100 or some other value that is
greater than 70 will also be given marks as right end of the disk is not
given.
Head moves:
● 40 → 45 = 5
● 45 → 60 = 15
● 60 → 70 = 10
● 70 → 0 (jump) = 70
● 0 → 10 = 10
● 10 → 20 = 10
● 20 → 35 = 15
Total = 135
FCFS: 0→10→20→30 = 30
SSTF: 0→10→20→30 = same
Need:
● P1 = 3
● P2 = 2
● P3 = 4
Total need = 9
Available = 12 − (3+4+2) = 3
Try:
● P1 (need 3) → OK
● P3 (need 4) → OK
Safe state
We are given:
● 4 processes arrive at time 0
● P1 = 6 ms, P3 = 2 ms, P4 = 4 ms
● Need to find P2 = ?
Step 1: Order processes by burst time (SJF): Let’s denote burst time of P2 as X.
Let’s try X = 8:
P3 2 0 0
P4 4 2 2
P1 6 6 6
P2 8 12 12
P2 0 0 0
P3 2 0 0
P4 4 2 2
P1 6 6 6
Avg = (0+0+2+6)/4 = 2 → too low
P3 0 0
P2 2 2
P4 5 5
P1 9 9
Avg = (0+2+5+9)/4 = 4
Try P2 = 1
| P2 | 0 | 0 | | P3 | 1 | 1 | | P4 | 3 | 3 | | P1 | 7 | 7 |
Try P2 = 5
P3 0 0
P4 2 2
P2 6 6
P1 11 11
Try P2 = 3
Try P2 = 1.5
Answer: P2 = 3 ms
Yes, in specific cases, Round Robin (RR) can give the same average waiting time as FCFS.
Example:
● Processes: P1 = 3, P2 = 4, P3 = 2
FCFS:
Proces Start WT
s
P1 0 0
P2 3 3
P3 7 7
→ Race condition occurs, as both processes may enter the critical section.
Process P1:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}
Process P2:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}
→ If 1 thread blocks (e.g., I/O), entire process blocks, so all 3 threads pause.
Processes: P1 = 1, P2 = 10, P3 = 10
Quantum = 4
FCFS:
Waiting times:
● P1: 0
● P2: 1
RR:
Time Process
0-1 P1
(done)
1-5 P2
5-9 P3
9-11 P2
11-13 P3
13-14 P2
14-15 P3
Waiting times:
● P1: 0
● P2: 8
● P3: 8
Given:
● P1 holds A
● P2 holds B
● P3 holds C
Safe guess:
● P1 holds A, requesting B
● P2 holds B, requesting C
● P1 → C
● P2 → A
● P3 → B
Graph: P1 → C, P2 → A, P3 → B → no cycle
Guess: P1 wants C, P2 wants A, P3 wants B
Example:
P1 holds A, needs B
P2 holds B, needs C
P3 holds C, needs A
But if:
Page reference: 2, 3, 2, 1, 5, 2, 4, 5, 3, 2
Frames = 3
Trace:
● 2 → miss [2]
● 3 → miss [2,3]
● 2 → hit
● 1 → miss [2,3,1]
● 5 → replace 2 → [5,3,1]
● 2 → replace 3 → [5,2,1]
● 4 → replace 1 → [5,2,4]
● 5 → hit
● 3 → replace 2 → [5,3,4]
● 2 → replace 4 → [5,3,2]
Replaced twice:
● re-added at 6th
Example:
● Hard link: Points to inode. File persists until all hard links are deleted
Segment 1:
● base = 500
Head moves:
● 40 → 45 = 5
● 45 → 60 = 15
● 60 → 70 = 10
● 70 → 0 (jump) = 70
● 0 → 10 = 10
● 10 → 20 = 10
● 20 → 35 = 15
Total = 135
FCFS: 0→10→20→30 = 30
SSTF: 0→10→20→30 = same
Need:
● P1 = 3
● P2 = 2
● P3 = 4
Total need = 9
Available = 12 − (3+4+2) = 3
Try:
● P1 (need 3) → OK
● P3 (need 4) → OK
Safe state