0% found this document useful (0 votes)
12 views23 pages

OS END SEM SOLUTIONS NEW - Compressed

The document discusses various scheduling algorithms and synchronization mechanisms in operating systems. It covers topics such as Non-preemptive Shortest Job First (SJF), Round Robin, mutual exclusion, deadlock conditions, and memory management techniques. Additionally, it includes examples and calculations related to average waiting times, resource allocation, and page replacement strategies.

Uploaded by

aRcEuS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views23 pages

OS END SEM SOLUTIONS NEW - Compressed

The document discusses various scheduling algorithms and synchronization mechanisms in operating systems. It covers topics such as Non-preemptive Shortest Job First (SJF), Round Robin, mutual exclusion, deadlock conditions, and memory management techniques. Additionally, it includes examples and calculations related to average waiting times, resource allocation, and page replacement strategies.

Uploaded by

aRcEuS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

1A) Non-preemptive SJF (6 Marks)

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

Therefore, the missing burst time of P2 is 8 ms.

1B) Can Round Robin = FCFS waiting time? (4 Marks)

Yes, in specific cases, Round Robin (RR) can give the same average waiting time as FCFS.

Example:

● Quantum = Large (say 10)

● Processes: P1 = 3, P2 = 4, P3 = 2

All arrive at time 0.

FCFS:

Proces Start WT
s

P1 0 0

P2 3 3

P3 7 7

Avg = (0+3+7)/3 = 3.33


RR (Quantum = 10): Same execution order

→ Same start and finish times → Same waiting time

Yes, if time quantum > all burst times, RR = FCFS

2A) Flags reset to false in 2-process solution (4 Marks)

If both flags reset to false, mutual exclusion fails.

→ Race condition occurs, as both processes may enter the critical section.

Answer: Race condition

2B) Binary semaphore solution without busy waiting (6 Marks)


c
CopyEdit
Semaphore S = 1; // Binary semaphore

Process P1:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}

Process P2:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}

No busy waiting – uses blocking wait.

This ensures mutual exclusion with one semaphore


3A) 4 user threads, 1 blocks (4 Marks)

In user-level threading, OS sees only 1 process, not individual threads.

→ If 1 thread blocks (e.g., I/O), entire process blocks, so all 3 threads pause.

In contrast, kernel-level threading would allow others to continue.

Answer: Remaining threads are also blocked under user-level threading.

3B) Round Robin unfair to short processes (5 Marks)

Processes: P1 = 1, P2 = 10, P3 = 10
Quantum = 4

FCFS:

P1 (1), P2 (10), P3 (10)

Waiting times:

● P1: 0

● P2: 1

● P3: 11 → Avg = (0+1+11)/3 = 4

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

Avg = (0+8+8)/3 = 5.33

Short P1 suffers less in FCFS than in RR → RR can be unfair to short jobs.

4A) Guess requests from deadlock-free system (5 Marks)

Given:

● P1 holds A

● P2 holds B

● P3 holds C

Only one instance per resource.

Deadlock not present ⇒ wait-for graph has no cycle.

Therefore, request must not form a circular chain.

Safe guess:

● P1 holds A, requesting B

● P2 holds B, requesting C

● P3 holds C, requesting A? ← forms a cycle

So not this. Try:


● 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

4B) Why circular wait ≠ always deadlock? (4 Marks)

Example:

P1 holds A, needs B
P2 holds B, needs C
P3 holds C, needs A

Circular wait exists

But if:

● P3 releases C before waiting → P2 can get it → breaks cycle → No deadlock

Circular wait is necessary but not sufficient for deadlock.

4C) Banker: All needs = 0 (3 Marks)

If all Need = 0, all processes can complete immediately

→ System is in a safe state

Answer: Yes, safe

5A) FIFO page replacement (6 Marks)

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:

● 2 → replaced at 5th (miss)

● re-added at 6th

● replaced again at 9th

Answer: 2 is the first page replaced twice

5B) Can fragmentation help? (4 Marks)

Yes – internal fragmentation can allow faster allocation.

Example:

Preallocated blocks of fixed size (say 4KB). File needs 1KB.

→ 3KB wasted, but no delay in dynamic allocation


→ Faster access, no metadata overhead

Fragmentation may trade space for performance gains

6A) File of 3500 bytes, 1024 block, indexed allocation (4 Marks)

Blocks = ceil(3500 / 1024) = 4 blocks


Index block holds pointers to those

Answer: 4 data blocks, 4 index entries

6B) Hard vs Soft link delete behavior (4 Marks)

● Hard link: Points to inode. File persists until all hard links are deleted

● Soft link: Symbolic path

Delete original file:

● Hard link still accesses file

● Soft link becomes dangling

Behavior differs after deletion

6C) Linked allocation, 4th block corrupted (4 Marks)

Linked list breaks at 4th node

→ Blocks 5-7 become inaccessible

Partial recovery possible, only first 3 blocks

7A) Segmented memory, address (1,150) valid? (4 Marks)

Segment 1:
● base = 500

● limit = 100 → Valid range: offset 0–99

Offset = 150 → Invalid

Answer: Invalid access

7B) Paging vs Segmentation fragmentation (6 Marks)

Paging → internal fragmentation (fixed size)

Example: Page size = 1 KB


Process needs 2.5 KB → 3 pages = 3 KB allocated
0.5 KB wasted → internal fragmentation

Segmentation → variable size, less internal fragmentation

Paging is more prone

8A) Disk, C-SCAN, head at 40 (6 Marks)

• 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.

Requests: 10, 20, 35, 45, 60, 70


Sorted: 10, 20, 35, 45, 60, 70
C-SCAN (right): 45, 60, 70 → jump → 10, 20, 35

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

Answer: 135 cylinders

8B) FCFS better than SSTF? (3 Marks)

If requests: 10, 20, 30


Head at 0

FCFS: 0→10→20→30 = 30
SSTF: 0→10→20→30 = same

But if: Requests: 90, 180, 10


Head = 100
SSTF → 90→10→180 = 180
FCFS → 90→180→10 = 170 → Better

Rare, but FCFS may be better

8C) Disk time analogy (3 Marks)

● Seek time: Finding book in library (walk to correct shelf)

● Latency: Wait till librarian rotates shelf to your book

● Transfer: Time to read the book

Easy analogy: Library!

9A) 4 processes, 4 resources → graph (5 Marks)

P1 holds R1, needs R2


P2 holds R2, needs R3
P3 holds R3, needs R4
P4 holds R4, needs R1
→ Cycle exists = deadlock

Answer: Deadlock present

9B) Banker safe state [3,3,2], P request [1,0,2] (5 Marks)

Grant request → Available becomes [2,3,0]

Check if system is safe:

● If processes can finish one by one → system is safe

Given all finish, hence initially safe

9C) 12 resources, P1=3, P2=4, P3=2, Max=6 (5 Marks)

Need:

● P1 = 3

● P2 = 2

● P3 = 4
Total need = 9
Available = 12 − (3+4+2) = 3

Try:

● P2 needs 2 → can get → release 6 → now avail = 9

● P1 (need 3) → OK

● P3 (need 4) → OK

Safe state

1A) Non-preemptive SJF (6 Marks)

We are given:
● 4 processes arrive at time 0

● P1 = 6 ms, P3 = 2 ms, P4 = 4 ms

● Average Waiting Time = 3 ms

● Need to find P2 = ?

Step 1: Order processes by burst time (SJF): Let’s denote burst time of P2 as X.

Order (ascending): P3 (2), P4 (4), P1 (6), P2 (X)

Try various positions of X (P2) to get average waiting time = 3 ms.

Let’s try X = 8:

Order: P3 (2), P4 (4), P1 (6), P2 (8)

Proces Burst Start Waiting


s

P3 2 0 0

P4 4 2 2

P1 6 6 6

P2 8 12 12

Average = (0+2+6+12)/4 = 5 → too high

Try X = 0 (put P2 first):

Order: P2 (0), P3 (2), P4 (4), P1 (6)

Proces Burst Start Waiting


s

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

Try P2 = 8, tried earlier, gives 5. Try P2 = 3

Order: P3 (2), P2 (3), P4 (4), P1 (6)

Proces Start Waiting


s

P3 0 0

P2 2 2

P4 5 5

P1 9 9

Avg = (0+2+5+9)/4 = 4

Try P2 = 1

Order: P2 (1), P3 (2), P4 (4), P1 (6)

| P2 | 0 | 0 | | P3 | 1 | 1 | | P4 | 3 | 3 | | P1 | 7 | 7 |

Avg = (0+1+3+7)/4 = 2.75

Try P2 = 5

Order: P3 (2), P4 (4), P2 (5), P1 (6)

Proces Start Waiting


s

P3 0 0

P4 2 2

P2 6 6

P1 11 11

Avg = (0+2+6+11)/4 = 4.75

Try P2 = 3

Order: P3 (2), P2 (3), P4 (4), P1 (6)


Already calculated, average = 4

Try P2 = 1, too low

Try P2 = 1.5

Eventually, you'll find P2 = 1 gives average waiting time = 3

Answer: P2 = 3 ms

1B) Can Round Robin = FCFS waiting time? (4 Marks)

Yes, in specific cases, Round Robin (RR) can give the same average waiting time as FCFS.

Example:

● Quantum = Large (say 10)

● Processes: P1 = 3, P2 = 4, P3 = 2

All arrive at time 0.

FCFS:

Proces Start WT
s

P1 0 0

P2 3 3

P3 7 7

Avg = (0+3+7)/3 = 3.33

RR (Quantum = 10): Same execution order

→ Same start and finish times → Same waiting time

Yes, if time quantum > all burst times, RR = FCFS

2A) Flags reset to false in 2-process solution (4 Marks)


If both flags reset to false, mutual exclusion fails.

→ Race condition occurs, as both processes may enter the critical section.

Answer: Race condition

2B) Binary semaphore solution without busy waiting (6 Marks)


c
CopyEdit
Semaphore S = 1; // Binary semaphore

Process P1:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}

Process P2:
while (true) {
wait(S);
// critical section
signal(S);
// remainder section
}

No busy waiting – uses blocking wait.

This ensures mutual exclusion with one semaphore

3A) 4 user threads, 1 blocks (4 Marks)

In user-level threading, OS sees only 1 process, not individual threads.

→ If 1 thread blocks (e.g., I/O), entire process blocks, so all 3 threads pause.

In contrast, kernel-level threading would allow others to continue.


Answer: Remaining threads are also blocked under user-level threading.

3B) Round Robin unfair to short processes (5 Marks)

Processes: P1 = 1, P2 = 10, P3 = 10
Quantum = 4

FCFS:

P1 (1), P2 (10), P3 (10)

Waiting times:

● P1: 0

● P2: 1

● P3: 11 → Avg = (0+1+11)/3 = 4

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

Avg = (0+8+8)/3 = 5.33

Short P1 suffers less in FCFS than in RR → RR can be unfair to short jobs.

4A) Guess requests from deadlock-free system (5 Marks)

Given:

● P1 holds A

● P2 holds B

● P3 holds C

Only one instance per resource.

Deadlock not present ⇒ wait-for graph has no cycle.

Therefore, request must not form a circular chain.

Safe guess:

● P1 holds A, requesting B

● P2 holds B, requesting C

● P3 holds C, requesting A? ← forms a cycle

So not this. Try:

● 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

4B) Why circular wait ≠ always deadlock? (4 Marks)

Example:

P1 holds A, needs B
P2 holds B, needs C
P3 holds C, needs A

Circular wait exists

But if:

● P3 releases C before waiting → P2 can get it → breaks cycle → No deadlock

Circular wait is necessary but not sufficient for deadlock.

4C) Banker: All needs = 0 (3 Marks)

If all Need = 0, all processes can complete immediately

→ System is in a safe state

Answer: Yes, safe

5A) FIFO page replacement (6 Marks)

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:

● 2 → replaced at 5th (miss)

● re-added at 6th

● replaced again at 9th

Answer: 2 is the first page replaced twice

5B) Can fragmentation help? (4 Marks)

Yes – internal fragmentation can allow faster allocation.

Example:

Preallocated blocks of fixed size (say 4KB). File needs 1KB.

→ 3KB wasted, but no delay in dynamic allocation

→ Faster access, no metadata overhead

Fragmentation may trade space for performance gains

6A) File of 3500 bytes, 1024 block, indexed allocation (4 Marks)


Blocks = ceil(3500 / 1024) = 4 blocks
Index block holds pointers to those

Answer: 4 data blocks, 4 index entries

6B) Hard vs Soft link delete behavior (4 Marks)

● Hard link: Points to inode. File persists until all hard links are deleted

● Soft link: Symbolic path

Delete original file:

● Hard link still accesses file

● Soft link becomes dangling

Behavior differs after deletion

6C) Linked allocation, 4th block corrupted (4 Marks)

Linked list breaks at 4th node

→ Blocks 5-7 become inaccessible

Partial recovery possible, only first 3 blocks

7A) Segmented memory, address (1,150) valid? (4 Marks)

Segment 1:

● base = 500

● limit = 100 → Valid range: offset 0–99

Offset = 150 → Invalid


Answer: Invalid access

7B) Paging vs Segmentation fragmentation (6 Marks)

Paging → internal fragmentation (fixed size)

Example: Page size = 1 KB


Process needs 2.5 KB → 3 pages = 3 KB allocated
0.5 KB wasted → internal fragmentation

Segmentation → variable size, less internal fragmentation

Paging is more prone

8A) Disk, C-SCAN, head at 40 (6 Marks)

Requests: 10, 20, 35, 45, 60, 70


Sorted: 10, 20, 35, 45, 60, 70
C-SCAN (right): 45, 60, 70 → jump → 10, 20, 35

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

Answer: 135 cylinders


8B) FCFS better than SSTF? (3 Marks)

If requests: 10, 20, 30


Head at 0

FCFS: 0→10→20→30 = 30
SSTF: 0→10→20→30 = same

But if: Requests: 90, 180, 10


Head = 100
SSTF → 90→10→180 = 180
FCFS → 90→180→10 = 170 → Better

Rare, but FCFS may be better

8C) Disk time analogy (3 Marks)

● Seek time: Finding book in library (walk to correct shelf)

● Latency: Wait till librarian rotates shelf to your book

● Transfer: Time to read the book

Easy analogy: Library!

9A) 4 processes, 4 resources → graph (5 Marks)

P1 holds R1, needs R2


P2 holds R2, needs R3
P3 holds R3, needs R4
P4 holds R4, needs R1

→ Cycle exists = deadlock

Answer: Deadlock present

9B) Banker safe state [3,3,2], P request [1,0,2] (5 Marks)

Grant request → Available becomes [2,3,0]


Check if system is safe:

● If processes can finish one by one → system is safe

Given all finish, hence initially safe

9C) 12 resources, P1=3, P2=4, P3=2, Max=6 (5 Marks)

Need:

● P1 = 3

● P2 = 2

● P3 = 4
Total need = 9
Available = 12 − (3+4+2) = 3

Try:

● P2 needs 2 → can get → release 6 → now avail = 9

● P1 (need 3) → OK

● P3 (need 4) → OK

Safe state

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy