Roll no: 23691A0540
Name:E.Dinesh Kumar
Department of computer science and
engineering
Sec:CSE-A
1) Apply the bankers algorithm by
Consider the following snapshot of
a system:
Allocatio Max Available
n
ABCD ABCD ABCD
P 00012 0012 1520
P1 1000 1750
P2 1354 2356
P3 0632 0652
P4 0014 0656
Answer the following questions
using the banker’s algorithm:
a. What is the content of the matrix
Need?
b. Is the system in a safe state?
Considering the following snapshot
of a system.
Solution:
Explanation of what’s asked:
Need matrix → Calculated as:
Need[i][j] = Max[i][j] - Allocation[i][j]
Safe state check → Use Banker’s Algorithm to find a
safe sequence, if it exists.
Step (a): Calculate the Need matrix
Formula:
{Need[i][j]} = {Max[i][j]} -{Allocation[i][j]}
Process Need(ABCD)
P0 0-0,0-0,1-1,2-2-
>0000
P1 1-1,7-0,5-0,0-0->0
750
P2 2-1, 3-3, 5-5,6-4-
>1 0 0 2
P3 0-0,6-6,5-3,2-2->0
020
P4 0-0,6-0,5-1,6-4->0
642
Find need matrix:
Step (b): Check if the system is in a safe state.
We use the Banker’s algorithm to find a safe sequence.
Initial Available: 1 5 2 0
We check which process can finish (Need ≤ Available).
1. Check P0:
Need: 0 0 0 0 ≤ 1 5 2 0 → Yes
Update Available: (1+0,5+0,2+1,0+2) → 1 5 3 2
Safe sequence so far: P0.
2. Check P1:
Need: 0 7 5 0 ≤ 1 5 3 2 → No
3. Check P2:
Need:1 0 0 2 ≤1 5 3 2 → Yes
Update Available 1+1,5+3,3+5,2+4) →2 8 8 6.
Safe sequence so far: P0 → P2
4. Check P1 again:
Need:0 7 5 0 ≤2 8 8 6 → Yes
Update Available 2+1,8+0,8+0,6+0) →3 8 8 6
Safe sequence so far: P0 → P2 → P1
5. Check P3:
Need:0 0 2 0 ≤3 8 8 6 → Yes
Update Available 3+0,8+6,8+3,6+2) →3 14 11 8
Safe sequence so far: P0 → P2 → P1 → P3.
6. Check P4:
Need:0 6 4 2 ≤3 14 11 8 → Yes
Update Available 3+0,14+0,11+1,8+4) →3 14 12 12
Final safe sequence:
process ABCD
P0 0000
P1 0750
P2 1002
P3 0020
P4 0642
b) Is the system in a safe state? → YES Safe sequence:
P0 → P2 → P1 → P3 → P4.
2)Consider the following page reference string: 1, 2,
3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4, 5, 4, 2.
Assuming demand paging with Three frames, how
many page faults would occur for the following
replacement algorithms?
• LRU replacement
• FIFO replacement
• Optimal replacement
Answer:
Page reference string:
1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4, 5, 4, 2
Number of frames: 3
We will count page faults for each of the three
algorithms.
Step Page Frames Fault/Hit
1 1 1 F
2 2 12 F
3 3 123 F
4 2 123 H
5 5 1235 F
6 6 2 3 5 6 F (1 out)
7 3 2356 H
8 4 3 5 6 4 F (2 out)
9 6 564 H
10 3 5 6 4 3 F (5 out)
11 7 6 4 3 7 F (5 out)
12 3 6437 H
13 1 4 3 7 1 F (6 out)
14 5 3 7 1 5 F (4 out)
15 3 7153 H
Step Page Frames Fault/Hit
16 6 1 5 3 6 F (7 out)
17 3 1536 H
18 4 5 3 6 4 F (1 out)
19 2 3 6 4 2 F (5 out)
20 4 3642 H
21 3 3642 H
22 4 3642 H
23 5 6 4 2 5 F (3 out)
FIFO Total:
Faults = 15
Hits = 23 - 15 = 8
Step 2: LRU (Least Recently Used)
We track the least recently used page.
Step Page Frames Fault/Hit
1 1 1 F
2 2 12 F
3 3 123 F
4 2 132 H
5 5 1325 F
6 6 3256 F (1 out)
7 3 2563 H
8 4 5634 F (2 out)
9 6 5346 H
10 3 5463 H
11 7 4637 F (5 out)
Step Page Frames Fault/Hit
12 3 4673 H
13 1 6731 F (4 out)
14 5 7315 F (6 out)
15 3 7153 H
16 6 1536 F (7 out)
17 3 1563 H
18 4 5634 F (1 out)
19 2 6342 F (5 out)
20 4 6324 H
21 3 6243 H
22 4 6234 H
23 5 2345 F (6 out)
LRU Total:
Faults = 15
Hits = 23 - 15 = 8
Optimal (MIN) Replacement
We replace the page that won’t be used for the longest time in the future.
Step Page Frames Fault/Hit
1 1 1 F
2 2 12 F
3 3 123 F
4 2 123 H
5 5 1235 F
6 6 2 3 5 6 F (1 out, used furthest)
7 3 2356 H
8 4 3 5 6 4 F (2 out)
9 6 3564 H
10 3 3564 H
11 7 5 6 4 7 F (3 out)
12 3 6 4 7 3 F (5 out)
13 1 4 7 3 1 F (6 out)
14 5 7 3 1 5 F (4 out)
15 3 7315 H
16 6 3 1 5 6 F (7 out)
17 3 3156 H
18 4 1 5 6 4 F (3 out)
19 2 5 6 4 2 F (1 out)
Step Page Frames Fault/Hit
20 4 5642 H
21 3 6423 F (5 out)
22 4 6234 H
23 5 2345 F (6 out)
Optimal Total:
Faults = 16
Hits = 23 -16 = 7
Final Summary
Algorithm Page Faults Page Hits
FIFO 15 8
LRU 15 8
Optimal 16 7
3) a. Suppose that a disk drive has 167
cylinders, numbered 18 to 184. The drive is
currently serving a request at cylinder 100.
The queue of pending requests, in FIFO
order, is:
55,58,39,18,90,160,150,38,184.What is the
total distance (in cylinders) that the disk
arm moves to satisfy all the pending
requests for each of the following disk-
scheduling algorithms?
a. FCFS b. SSTF c. SCAN d. C-SCAN
b. Discuss about file system mounting.
Answer :
(a) Disk Scheduling Problem
Given:
Total cylinders = 167, numbered 18 to 184
Current head position = 100
Pending requests in FIFO:
55, 58, 39, 18, 90, 160, 150, 38, 184
We need to calculate total head movement (in cylinders)
for:
FCFS (First-Come, First-Served)
We serve in given order:
100 → 55 → 58 → 39 → 18 → 90 → 160 → 150 →
38 → 184
Moveme Distan
nt ce
100 →
45
55
55 → 58 3
58 → 39 19
39 → 18 21
18 → 90 72
Moveme Distan
nt ce
90 →
70
160
160 →
10
150
150 →
112
38
38 →
146
184
Total 498
FCFS Total = 498 cylinders
SSTF (Shortest Seek Time First)
At each step, go to the closest request.
Start: 100
Requests: [55, 58, 39, 18, 90, 160, 150, 38, 184]
100 → 90 (10)
90 → 58 (32)
58 → 55 (3)
55 → 39 (16)
39 → 38 (1)
38 → 18 (20)
18 → 150 (132)
150 → 160 (10)
160 → 184 (24)
Moveme Distan
nt ce
100 →
10
90
90 → 58 32
58 → 55 3
55 → 39 16
39 → 38 1
38 → 18 20
18 →
132
150
150 →
10
160
160 →
24
184
Moveme Distan
nt ce
Total 248
SCAN (Elevator Algorithm)
The arm moves toward one end, serves all requests in
that direction, then reverses.
Assume moving toward 184 first.
Requests ≥100: 160,150,184 → sorted:
150,160,184
Requests <100: 90, 58,55,39,38,18 → sorted:
90,58,55,39,38,18
Path:
100 → 150 →160 →184 → then reverse → 90 →58
→55 →39 →38 →18
Moveme Distan
nt ce
100→15
50
0
150→16
10
0
160→18 24
Moveme Distan
nt ce
4
184→90 94
90→58 32
58→55 3
55→39 16
39→38 1
38→18 20
Total 250
C-SCAN (Circular SCAN)
Arm goes toward end, jumps to start, then continues.
Path:
100 →150 →160 →184 → jump to 18 →18 →38 →39
→55 →58 →90
Moveme Distan
nt ce
100→15
50
0
Moveme Distan
nt ce
150→16
10
0
160→18
24
4
184→18 166
18→38 20
38→39 1
39→55 16
55→58 3
58→90 32
Total 322
C-SCAN Total = 322 cylinders
Final Summary:
Algorith Total Movement
m (cylinders)
FCFS 498
Algorith Total Movement
m (cylinders)
SSTF 248
SCAN 250
C-SCAN 322
(b) File System Mounting
Definition:
Mounting a file system means
making it accessible to the
operating system and users by
attaching it to the existing
directory structure.
Key Points:
When you insert a disk or
storage device (like a USB drive),
the OS mounts its file system.
This attaches the root of the new
file system (e.g., /dev/sdb1) to
an existing directory (e.g.,
/mnt/usb or /media).
After mounting, files and
directories on the device can be
accessed like part of the main
file system.
Steps in Mounting:
1. OS reads file system
metadata (like the superblock).
2. Checks if the file system is
valid and not corrupted.
3. Links the file system tree into
the main directory tree at a
mount point.
4. Users can now access it using
normal file paths.
Example in Linux:
mount /dev/sdb1 /mnt/usb
Important Concepts:
Mount point → directory where
the device is attached.
Unmounting → safely detaching
the file system (umount
/mnt/usb) before removing the
device.
Automatic mounting → some OS
(like Windows) auto-mount on
plug-in.