PART A
1.On a Linux-based system, a process holding an array of 1 million integers executes fork(). The child process only reads the array to compute a sum, while the parent continues modifying the array.
If the parent modifies 10% of the pages and the array spans 2000 pages:
-
How many physical copies of the array exist immediately after
fork()?
-
How many pages get duplicated due to the modifications?
✅ Answer
Key Concepts Involved
-
fork() in Linux uses Copy-On-Write (COW)
-
Initially, parent and child share the same physical pages
-
A page is copied only when one process modifies it
Step-by-Step Reasoning
1. Immediately after fork()
-
No pages are copied yet
-
Parent and child share all 2000 pages
-
So:
👉 Physical copies of the array = 1 (shared)
2. When the parent modifies 10% of pages
-
Total pages = 2000
-
Modified pages = 10% of 2000 = 200 pages
Because of COW:
-
These 200 pages are duplicated
-
Parent gets private copies of these pages
-
Child continues using original pages (since it only reads)
2.On a system with n processors, what is the minimum and maximum number of processes that can be in the following states at any instant?
✅ Answer
🔹 1. Running State
-
A processor can execute only one process at a time
-
With n processors, up to n processes can run simultaneously
👉 Minimum: 0 (if no process is ready to run)
👉 Maximum: n
🔹 2. Ready State
-
Ready processes are those waiting for CPU allocation
👉 Minimum: 0 (if all processes are either running or blocked)
👉 Maximum: Unbounded (depends on total number of processes in the system)
🔹 3. Blocked State
-
Blocked processes are waiting for I/O or some event
👉 Minimum: 0 (if no process is waiting)
👉 Maximum: Unbounded (depends on how many processes are waiting for events)
3.Processes P1 and P2 use the following code for synchronization. Assume flag is a shared variable initialized to false.
-
Does this guarantee mutual exclusion?
-
Can it lead to deadlock?
✅ Answer
🔹 1. Mutual Exclusion — ❌ Not Guaranteed
This solution fails to guarantee mutual exclusion.
💡 Why?
The check and update of flag are not atomic.
⚠️ Possible Interleaving:
-
P1 checks
flag == false → TRUE
-
Context switch happens before setting
flag = true
-
P2 checks
flag == false → TRUE
-
Both processes set
flag = true
-
Both enter
criticalSection() ❌
👉 Result: Two processes are in the critical section simultaneously → Violation of mutual exclusion
🔹 2. Deadlock — ❌ No, it does not lead to deadlock
💡 Why?
-
A process does not wait if
flag == true
-
It simply skips the critical section and continues
-
There is no circular waiting
👉 Result: No deadlock occurs
4.An operating system has 3 processes, each requiring 2 units of a resource R.
What is the minimum number of instances of R required so that the system is deadlock-free?
✅ Answer
👉 Minimum number of instances required = 4
💡 Explanation
To ensure a system is deadlock-free, we must prevent a situation where:
-
Each process holds one unit of resource R
-
And waits indefinitely for one more unit
🔍 Worst-Case Scenario
-
Total processes = 3
-
Each needs 2 units
-
Suppose each process acquires 1 unit
👉 Resources allocated = 3 units
👉 Each process still needs 1 more unit
If only 3 units exist:
-
No free resource is available
-
All processes are stuck waiting ❌ → Deadlock
For n processes, each requiring at most k instances of a resource:
5.On a system using demand-paged memory:
-
Memory access time (no page fault) = 120 ns
-
Page fault service time = 5 ms
-
Desired effective access time (EAT) = 1 μs
👉 What page fault rate (p) is required?
✅ Solution
🔹 Step 1: Convert all units to nanoseconds
-
-
-
1
🔹 Step 2: Use EAT Formula
🔹 Step 3: Solve
🎯 Final Answer
👉 Page fault rate ≈ 0.000176
👉 ≈ 0.0176%
💡 Key Insight
-
Even a tiny page fault rate (~0.018%) significantly impacts performance
-
This highlights why:
-
Page faults must be extremely rare
-
Good locality of reference is critical
6.A computer has four page frames. The following information is given:
| Page | TLD | TLA | R | M |
|---|
| 0 | 126 | 280 | 1 | 0 |
| 1 | 230 | 265 | 0 | 1 |
| 2 | 240 | 270 | 1 | 0 |
| 3 | 110 | 285 | 1 | 1 |
Where:
-
TLD = Time of Last Loading
-
TLA = Time of Last Access
-
R = Reference bit
-
M = Modified bit
👉 Which page will be replaced using:
-
FIFO
-
LRU
-
Modified Clock algorithm
✅ Answer
🔹 1. FIFO (First-In, First-Out)
-
Replace the page with the smallest TLD (oldest loaded)
👉 Replaced Page = 3
🔹 2. LRU (Least Recently Used)
-
Replace the page with the smallest TLA (least recently accessed)
👉 Replaced Page = 1
🔹 3. Modified Clock Algorithm
This algorithm prefers pages in this order:
-
(R=0, M=0) → best candidate
-
(R=0, M=1)
-
(R=1, M=0)
-
(R=1, M=1) → worst candidate
👉 Only Page 1 falls in (0,1)
👉 Replaced Page = 1
📊 Final Summary
| Algorithm | Page Replaced |
|---|
| FIFO | 3 |
| LRU | 1 |
| Modified Clock | 1 |
7.A computer system uses a hard disk with the following specifications:
-
Rotation speed = 7200 RPM
-
Average seek time = 9 ms
-
Maximum transfer rate = 105 MB/s
👉 Calculate the total average access time to read a disk block of 8 KB.
✅ Solution
Total disk access time consists of:
🔹 1. Seek Time
Given directly:
👉 Seek time = 9 ms
🔹 2. Rotational Latency
-
7200 RPM = 7200 rotations per minute
-
Time per rotation:
-
Average rotational latency = half rotation:
👉 Rotational latency ≈ 4.17 ms
🔹 3. Transfer Time
-
Transfer rate = 105 MB/s
-
Block size = 8 KB = 8 / 1024 MB = 0.0078125 MB
👉 Transfer time ≈ 0.074 ms
🎯 Final Answer
👉 Total average access time ≈ 13.24 ms
8.A user wishes to let his collaborators access some of his files, but expects the OS to:
-
Prevent collaborators from accessing other files
-
Prevent non-collaborators from accessing any of his files
👉 Explain how this is achieved in a Linux system, jointly by the user and the OS.
✅ Answer (Linux Context)
This is achieved through a combination of:
-
User actions (policy definition)
-
OS enforcement (permission checks)
1. Role of the User
The user organizes access control using:
✅ (a) Groups
-
Create a group for collaborators:
-
Add collaborators to the group:
✅ (b) File Ownership
-
Assign files to the group:
✅ (c) Permissions
Linux uses rwx permissions for:
Example:
| Role | Permission |
|---|
| Owner | read/write |
| Group (collaborators) | read |
| Others | no access |
👉 This ensures:
-
Collaborators can access only shared files
-
Others cannot access them
✅ (d) Restricting Private Files
For private files:
👉 Only the owner can access
✅ (e) Directory Permissions
-
Only owner + group can enter the directory
Role of the Operating System
The Linux OS enforces security via:
✅ (a) Access Control Checks
-
Every file access request is checked against:
-
User ID (UID)
-
Group ID (GID)
-
File permission bits
✅ (b) Process Credentials
-
Each process runs with a user identity
-
OS ensures:
-
A process cannot access files beyond its permissions
✅ (c) Isolation
-
Users cannot bypass permissions
-
Direct disk access is restricted by the kernel
PART B
9a)Ten independent processes start at time t = 0. Each process executes a loop where every iteration consists of:
-
CPU burst = 50 ms
-
I/O time = 200 ms
System details:
-
Scheduling: Round Robin (RR)
-
Time quantum = 20 ms
-
Context switch overhead = 3 ms
👉 Find the response time of the first process.
✅ Key Concept
👉 Response time = Time from arrival to first CPU allocation
So we only care about:
-
When does Process P1 get CPU for the first time?
🔍 Step-by-Step Analysis
🔹 All processes arrive at t = 0
🔹 Round Robin Execution
Each process gets:
-
20 ms CPU
-
Then 3 ms context switch
👉 Total per process slot:
🔹 When does P1 execute?
Since all arrive at the same time, P1 is scheduled first.
👉 It immediately gets CPU at t = 0
🎯 Final Answer
👉 Response time of P1 = 0 ms
💡 Important Insight (for students)
This is a tricky question:
-
Most students overthink and simulate the full schedule ❌
-
But response time depends only on first CPU access
🧩 Follow-up (Better Exam Variant)
If the question were:
What is the response time of P5?
Then:
9b)A hypothetical operating system provides a system call that allows a process to request memory allocation.
An experienced programmer advises:
“If your program makes many small requests for memory, you can improve its performance by combining them into a single request and making only one system call.”
👉 Explain why this advice makes sense.
✅ Answer
The advice is correct because system calls are expensive operations, and reducing their number improves performance.
🔍 Explanation
🔹 1. System Call Overhead
Each memory allocation request involves a system call, which requires:
-
Switching from user mode → kernel mode
-
Performing allocation logic inside the OS
-
Switching back kernel mode → user mode
👉 This involves:
-
Context switching
-
CPU pipeline disruption
-
Additional bookkeeping
⚠️ Even if the allocation is small, the overhead is relatively large
🔹 2. Cost of Many Small Requests
If a program makes many small allocations:
-
Each request incurs full system call overhead
-
Total overhead becomes significant:
Total cost=n×(system call overhead)
🔹 3. Benefit of Combining Requests
If requests are combined:
-
Only one system call is made
-
Memory is allocated in bulk
-
Program can internally manage this memory
👉 Result:
-
Reduced mode switches
-
Better CPU efficiency
-
Lower total execution time
10a)Consider the following code:
👉 If the code runs successfully:
-
How many new processes are created?
-
Draw the process tree
✅ Key Idea
-
fork() returns:
-
0 in the child
-
>0 (child PID) in the parent
👉 Condition:
-
Child (childpid = 0) → condition TRUE → breaks loop
-
Parent (childpid > 0) → condition FALSE → continues loop
🔍 Step-by-Step Execution
Loop runs from i = 1 to 4
🔹 Iteration 1 (i = 1)
-
P0 creates P1
-
P1 breaks out of loop
-
P0 continues
👉 Processes so far: P0, P1
🔹 Iteration 2 (i = 2)
-
P0 creates P2
-
P2 breaks
-
P0 continues
👉 Processes: P0, P1, P2
🔹 Iteration 3 (i = 3)
-
P0 creates P3
-
P3 breaks
-
P0 continues
👉 Processes: P0, P1, P2, P3
🔹 Iteration 4 (i = 4)
-
P0 creates P4
-
P4 breaks
-
P0 continues (loop ends)
👉 Processes: P0, P1, P2, P3, P4
🎯 Final Answer
🔹 Number of new processes created:
👉 4 new processes
🌳 Process Tree
💡 Key Insight
-
Only the parent continues the loop
-
Each iteration creates exactly one child
-
Children do not create further processes
10b)An OS supports both user-level threads (ULT) and kernel-level threads (KLT). A developer proposes:
-
G1: CPU-bound task → use KLT on multiprocessor systems; otherwise use ULT
-
G2: I/O-bound task → use ULT if no KLT exist in the process; otherwise use KLT
👉 Do you agree or disagree? Justify.
✅ Answer
👉 Partially agree with G1, but G2 is flawed / oversimplified
🔍 Evaluation
🔹 G1: CPU-bound tasks
Use KLT on multiprocessors; otherwise ULT
✔️ Mostly Correct
-
Multiprocessor system:
-
KLTs allow true parallelism (threads run on different CPUs)
-
ULTs cannot exploit multiple CPUs (managed in user space)
-
Single processor:
-
No parallelism benefit from KLT
-
ULT avoids kernel overhead → can be more efficient
👉 Conclusion:
✔️ Agree with G1 (generally correct)
⚠️ Minor caveat:
-
Even on single CPU, KLT may still be useful for preemption and fairness
🔹 G2: I/O-bound tasks
Use ULT if no KLT exist; otherwise use KLT
❌ Problematic / Incomplete
⚠️ Issue 1: Blocking Problem with ULT
-
In pure ULT model:
-
If one thread performs a blocking system call (I/O)
-
Entire process blocks ❌
👉 This makes ULT bad for I/O-bound tasks in many cases
⚠️ Issue 2: Oversimplification
-
The decision should depend on:
-
Whether OS supports non-blocking I/O
-
Whether there is M:N threading
-
Whether kernel provides asynchronous I/O
👉 Not just “presence of KLT”
✔️ Better Guideline
-
Use KLT for I/O-bound tasks when:
-
Blocking I/O is involved
-
You want concurrency during I/O
-
ULT can be used only if:
-
Non-blocking I/O or async mechanisms exist
-
Thread library handles scheduling efficiently
11a)Consider the following solution:
A hungry philosopher first picks up his left fork;
if his right fork is available, he picks it up and eats;
otherwise, he puts down the left fork and repeat the cycle.
👉 Comment on the correctness of this solution.
✅ Answer
👉 This solution avoids deadlock, but does not guarantee freedom from starvation and livelock.
🔍 Analysis
🔹 1. Deadlock — ❌ Avoided
-
In the classic deadlock scenario:
-
Each philosopher holds one fork and waits for the other → circular wait
-
In this solution:
-
A philosopher releases the left fork if the right fork is unavailable
-
So no philosopher holds a fork indefinitely while waiting
👉 Circular wait condition is broken
👉 Deadlock cannot occur
🔹 2. Starvation — ⚠️ Possible
-
A philosopher may repeatedly:
-
Pick up left fork
-
Fail to get right fork
-
Release and retry
-
Meanwhile, neighbors may continuously:
👉 This philosopher may never get both forks
👉 Starvation is possible
🔹 3. Livelock — ⚠️ Possible
-
All philosophers may:
-
Pick left fork simultaneously
-
Fail to get right fork
-
Release forks
-
Retry at the same time
👉 System keeps changing state but no progress is made
👉 This is livelock
11b) A multithreaded web server maintains a cache using a hash table (1024 buckets). Each bucket contains a doubly linked list of cached pages.The cache supports three operations: insert, lookup, and delete. It is proposed to use mutex locks for synchronization.
👉 Discuss the pros and cons of the following locking strategies:
-
One mutex for the entire cache
-
One mutex per bucket
-
One mutex per bucket + one per node
✅ Answer
🔹 (i) One Mutex for Entire Cache
✔️ Pros
-
Simple to implement
-
Easy to ensure correctness
-
No risk of deadlock
-
Minimal design complexity
❌ Cons
-
Poor concurrency
-
Only one thread can access the cache at a time
-
Becomes a bottleneck under high load
-
Threads performing lookup (read) still block each other
👉 Use case: Small systems or low contention scenarios
🔹 (ii) One Mutex per Bucket
✔️ Pros
-
Better concurrency
-
Threads accessing different buckets can proceed in parallel
-
Reduces contention significantly
-
Good balance between performance and complexity
❌ Cons
-
Threads accessing the same bucket still serialize
-
Performance depends on hash distribution
-
Slightly more complex than global lock
👉 Use case: Most practical and commonly used approach
🔹 (iii) One Mutex per Bucket + One per Node
✔️ Pros
-
Maximum concurrency
-
Multiple threads can operate on the same bucket simultaneously
-
Fine-grained locking allows:
-
Parallel traversal of linked lists
-
Better performance for large buckets
❌ Cons
-
High complexity
-
Difficult to implement correctly
-
Risk of deadlocks
-
Need careful lock ordering
-
Increased locking overhead
-
Harder to debug and maintain
👉 Use case: High-performance systems with heavy contention
📊 Summary Comparison
| Strategy | Concurrency | Complexity | Risk | Performance |
|---|
| Global mutex | Low | Low | Low | Poor under load |
| Per-bucket mutex | Medium–High | Medium | Low | Good |
| Per-bucket + per-node | Very High | High | High | Best (if done correctly) |
12a)Given:A system has four resource types:
Total Resources
-
A = 15, B = 6, C = 9, D = 10
Allocation and Maximum Demand
| Process | Allocation (A B C D) | Max (A B C D) |
|---|
| P0 | 2 0 2 1 | 9 5 5 5 |
| P1 | 0 1 1 1 | 2 2 3 3 |
| P2 | 4 1 0 2 | 7 5 4 4 |
| P3 | 1 0 0 1 | 3 3 3 2 |
| P4 | 1 1 0 0 | 5 2 2 1 |
| P5 | 1 0 1 1 | 4 4 4 4 |
👉 Is the system in a safe state?
✅ Step 1: Compute Available Resources
🔹 Total Allocated
| Resource | Sum |
|---|
| A | 2+0+4+1+1+1 = 9 |
| B | 0+1+1+0+1+0 = 3 |
| C | 2+1+0+0+0+1 = 4 |
| D | 1+1+2+1+0+1 = 6 |
🔹 Available
🔹 Step 2: Compute Need = Max − Allocation
| Process | Need (A B C D) |
|---|
| P0 | 7 5 3 4 |
| P1 | 2 1 2 2 |
| P2 | 3 4 4 2 |
| P3 | 2 3 3 1 |
| P4 | 4 1 2 1 |
| P5 | 3 4 3 3 |
🔹 Step 3: Find Safe Sequence
Initial Available = (6, 3, 5, 4)
✔️ P1 can execute
Need (2,1,2,2) ≤ Available
New Available:
✔️ P3 can execute
Need (2,3,3,1) ≤ (6,4,6,5)
New Available:
✔️ P4 can execute
Need (4,1,2,1) ≤ (7,4,6,6)
New Available:
✔️ P2 can execute
Need (3,4,4,2) ≤ (8,5,6,6)
New Available:
✔️ P5 can execute
Need (3,4,3,3) ≤ (12,6,6,8)
New Available:
✔️ P0 can execute
Need (7,5,3,4) ≤ (13,6,7,9)
New Available:
🎯 Final Answer
👉 Yes, the system is in a SAFE state
🔐 Safe Sequence
12b)A shared variable y, initially 10, is accessed by two concurrent processes A and B. Process A reads y from memory, adds 5 to it, and writes the result back to memory. Process B reads y from memory, subtracts 3 from it, and writes the result back to memory. Before reading y, each process performs a P (wait) operation on a counting semaphore T. After writing the updated value back to memory, the process performs a V (signal) operation on T. If the semaphore T is initialized to 1, what is the maximum possible value of y after both processes complete execution? Justify your answer.
✅ Key Concept
-
Semaphore T = 1 → acts as a mutex
-
Ensures mutual exclusion
-
Only one process executes its critical section at a time
👉 Therefore:
-
No race condition
-
Execution becomes sequential (one after the other)
🔍 Possible Execution Orders
Since mutual exclusion is enforced, only two valid orders exist:
🔹 Case 1: A executes first, then B
Process A:
Process B:
👉 Final value = 12
🔹 Case 2: B executes first, then A
Process B:
Process A:
👉 Final value = 12
🎯 Final Answer
👉 Maximum possible value of y = 12
13a)Translate the logical address 0001010010111010 into its corresponding physical address under a segmentation system with a maximum segment size of 1024, using a segment table where the base address of each segment is determined as: 22 + 4,096 × segment number .
Given:
-
Segmentation system
-
Maximum segment size = 1024 = 2¹⁰
-
Segment base address =
✅ Step 1: Split Logical Address
-
Logical address = 16 bits
-
Max segment size = 210 ⇒ offset = 10 bits
-
Remaining = 6 bits for segment number
🔹 Segment Number (first 6 bits)
🔹 Offset (last 10 bits)
Convert offset to decimal:
✅ Step 2: Compute Base Address
✅ Step 3: Compute Physical Address
Physical Address=Base+Offset
🎯 Final Answer
👉 Physical Address = 20688 (decimal)
13b)A computer provides each process with 65,536 bytes of address space divided into pages of 4096 bytes each. A particular process has a text size of 32,768 bytes, a data size of 16,386 bytes, and a stack size of 15,870 bytes.Will this process fit in the machine’s address space? Suppose that instead of 4096 bytes, the page size was 512 bytes, would it then fit? Each page must contain either text, data, or stack, not a mixture of two or three of them.
- Virtual address space per process = 65,536 bytes (64 KB)
-
Page size:
-
Case 1: 4096 bytes
-
Case 2: 512 bytes
Process memory:
-
Text = 32,768 bytes
-
Data = 16,386 bytes
-
Stack = 15,870 bytes
👉 Each page can contain only one type (no mixing)
✅ Step 1: Total Available Pages
🔹 Case 1: Page size = 4096 bytes
🔹 Case 2: Page size = 512 bytes
✅ Step 2: Pages Required (Case 1: 4096 bytes)
🔹 Text
🔹 Data
🔹 Stack
🔹 Total Pages Needed
👉 Available = 16 pages
👉 Required = 17 pages
❌ Does NOT fit
✅ Step 3: Pages Required (Case 2: 512 bytes)
🔹 Text
🔹 Data
🔹 Stack
🔹 Total Pages Needed
👉 Available = 128 pages
👉 Required = 128 pages
✔️ Fits exactly
🎯 Final Answer
| Page Size | Fits? |
|---|
| 4096 bytes | ❌ No |
| 512 bytes | ✔️ Yes |
14a) Consider the following C program:
int X[N], step = M;
for (int i = 0; i < N; i += step)
X[i] = X[i] + 1;
If this program is run on a machine with a 4-KB page size and 64-entry TLB, what values of M and N will cause a TLB miss for every execution of the inner loop?
Page size = 4 KB = 4096 bytes
TLB entries = 64
Assume int = 4 bytes
✅ Key Idea
To get a TLB miss every time:
-
Each access must go to a different page
-
And we must never reuse a page already in TLB
🔍 Step 1: Elements per Page
🔹 Step 2: Condition for Different Page Access
We want each X[i] to be on a new page.
👉 So:
-
If → multiple accesses within same page → TLB hit occurs ❌
-
If → each access jumps to a new page ✔️
🔹 Step 3: Condition to Overflow TLB
TLB can hold 64 entries.
To ensure every access is a miss:
-
We must access more than 64 distinct pages without reuse
👉 So:
🔹 Step 4: Combine Conditions
Final Conditions:
🎯 Example Values
-
-
Then:
-
Each access → new page
-
Total pages accessed = 64+
-
TLB cannot hold all → continuous eviction
👉 Every iteration → TLB miss
14b)Consider the following page reference string:
1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.
With a frame allocation of 4, determine the number of page faults for the FIFO, optimal and LRU page replacement policies.
🔹 1. FIFO (First-In First-Out)
👉 Replace oldest loaded page
| Step | Ref | Frame1 | Frame2 | Frame3 | Frame4 | Fault/Hit |
|---|
| 1 | 1 | 1 | - | - | - | F |
| 2 | 2 | 1 | 2 | - | - | F |
| 3 | 3 | 1 | 2 | 3 | - | F |
| 4 | 4 | 1 | 2 | 3 | 4 | F |
| 5 | 2 | 1 | 2 | 3 | 4 | H |
| 6 | 1 | 1 | 2 | 3 | 4 | H |
| 7 | 5 | 5 | 2 | 3 | 4 | F |
| 8 | 6 | 5 | 6 | 3 | 4 | F |
| 9 | 2 | 5 | 6 | 2 | 4 | F |
| 10 | 1 | 5 | 6 | 2 | 1 | F |
| 11 | 2 | 5 | 6 | 2 | 1 | H |
| 12 | 3 | 3 | 6 | 2 | 1 | F |
| 13 | 7 | 3 | 7 | 2 | 1 | F |
| 14 | 6 | 3 | 7 | 6 | 1 | F |
| 15 | 3 | 3 | 7 | 6 | 1 | H |
| 16 | 2 | 3 | 7 | 6 | 2 | F |
| 17 | 1 | 1 | 7 | 6 | 2 | F |
| 18 | 2 | 1 | 7 | 6 | 2 | H |
| 19 | 3 | 1 | 3 | 6 | 2 | F |
| 20 | 6 | 1 | 3 | 6 | 2 | H |
👉 Total FIFO faults = 14
🔹 2. LRU (Least Recently Used)
👉 Replace least recently used page
| Step | Ref | Frame1 | Frame2 | Frame3 | Frame4 | Fault/Hit |
|---|
| 1 | 1 | 1 | - | - | - | F |
| 2 | 2 | 1 | 2 | - | - | F |
| 3 | 3 | 1 | 2 | 3 | - | F |
| 4 | 4 | 1 | 2 | 3 | 4 | F |
| 5 | 2 | 1 | 2 | 3 | 4 | H |
| 6 | 1 | 1 | 2 | 3 | 4 | H |
| 7 | 5 | 1 | 2 | 5 | 4 | F |
| 8 | 6 | 1 | 2 | 5 | 6 | F |
| 9 | 2 | 1 | 2 | 5 | 6 | H |
| 10 | 1 | 1 | 2 | 5 | 6 | H |
| 11 | 2 | 1 | 2 | 5 | 6 | H |
| 12 | 3 | 1 | 2 | 3 | 6 | F |
| 13 | 7 | 1 | 2 | 3 | 7 | F |
| 14 | 6 | 6 | 2 | 3 | 7 | F |
| 15 | 3 | 6 | 2 | 3 | 7 | H |
| 16 | 2 | 6 | 2 | 3 | 7 | H |
| 17 | 1 | 6 | 2 | 3 | 1 | F |
| 18 | 2 | 6 | 2 | 3 | 1 | H |
| 19 | 3 | 6 | 2 | 3 | 1 | H |
| 20 | 6 | 6 | 2 | 3 | 1 | H |
👉 Total LRU faults = 10
🔹 3. Optimal
👉 Replace page used farthest in future
| Step | Ref | Frame1 | Frame2 | Frame3 | Frame4 | Fault/Hit |
|---|
| 1 | 1 | 1 | - | - | - | F |
| 2 | 2 | 1 | 2 | - | - | F |
| 3 | 3 | 1 | 2 | 3 | - | F |
| 4 | 4 | 1 | 2 | 3 | 4 | F |
| 5 | 2 | 1 | 2 | 3 | 4 | H |
| 6 | 1 | 1 | 2 | 3 | 4 | H |
| 7 | 5 | 1 | 2 | 3 | 5 | F |
| 8 | 6 | 1 | 2 | 3 | 6 | F |
| 9 | 2 | 1 | 2 | 3 | 6 | H |
| 10 | 1 | 1 | 2 | 3 | 6 | H |
| 11 | 2 | 1 | 2 | 3 | 6 | H |
| 12 | 3 | 1 | 2 | 3 | 6 | H |
| 13 | 7 | 1 | 2 | 3 | 7 | F |
| 14 | 6 | 1 | 2 | 3 | 6 | F |
| 15 | 3 | 1 | 2 | 3 | 6 | H |
| 16 | 2 | 1 | 2 | 3 | 6 | H |
| 17 | 1 | 1 | 2 | 3 | 6 | H |
| 18 | 2 | 1 | 2 | 3 | 6 | H |
| 19 | 3 | 1 | 2 | 3 | 6 | H |
| 20 | 6 | 1 | 2 | 3 | 6 | H |
👉 Total Optimal faults = 8
📊 Final Summary
| Algorithm | Page Faults |
|---|
| FIFO | 14 |
| LRU | 10 |
| Optimal | 8 |
15a)The disk controller for a hypothetical disk with 200 tracks receives the following sequence of disk track requests
27, 129, 110, 186, 147, 41, 10, 64, 120.
Assume that the disk head is initially positioned over track 100 and is moving in the direction of decreasing track number. Given that a seek between adjacent tracks takes 3ms, determine the better policy between SSTF and ELEVATOR algorithms if the judgement criterion is total seek time to serve all the requests. ELEVATOR and CLOOK algorithms if the judgement criterion is total seek time to serve all the requests.
Given
-
Tracks: 0–199 (200 tracks)
-
Initial head position: 100
-
Initial direction: towards lower tracks
-
Requests:
-
Seek time per track = 3 ms
🔹 1. SSTF (Shortest Seek Time First)
👉 Always go to closest request
Step-by-step movement
| Step | From → To | Distance |
|---|
| 100 → 110 | 10 | |
| 110 → 120 | 10 | |
| 120 → 129 | 9 | |
| 129 → 147 | 18 | |
| 147 → 186 | 39 | |
| 186 → 64 | 122 | |
| 64 → 41 | 23 | |
| 41 → 27 | 14 | |
| 27 → 10 | 17 | |
🔹 Total movement
👉 Total seek time:
🔹 2. Elevator (SCAN)
👉 Move in one direction (down), then reverse
Order (initially moving ↓):
Step-by-step
| Step | Movement | Distance |
|---|
| 100 → 64 | 36 | |
| 64 → 41 | 23 | |
| 41 → 27 | 14 | |
| 27 → 10 | 17 | |
| 10 → 110 | 100 | |
| 110 → 120 | 10 | |
| 120 → 129 | 9 | |
| 129 → 147 | 18 | |
| 147 → 186 | 39 | |
🔹 Total movement
👉 Total seek time:
🔹 3. C-LOOK
👉 Move in one direction, then jump to lowest request (no servicing during return)
Order:
Step-by-step
| Step | Movement | Distance |
|---|
| 100 → 64 | 36 | |
| 64 → 41 | 23 | |
| 41 → 27 | 14 | |
| 27 → 10 | 17 | |
| 10 → 186 | 176 | |
| 186 → 147 | 39 | |
| 147 → 129 | 18 | |
| 129 → 120 | 9 | |
| 120 → 110 | 10 | |
🔹 Total movement
👉 Total seek time:
📊 Final Comparison
| Algorithm | Total Movement | Seek Time |
|---|
| SSTF | 262 | 786 ms |
| SCAN (Elevator) | 266 | 798 ms |
| C-LOOK | 342 | 1026 ms |
🎯 Final Answer
✔️ Better between SSTF and Elevator:
👉 SSTF is better (786 ms < 798 ms)
✔️ Better between Elevator and C-LOOK:
👉 Elevator (SCAN) is better (798 ms < 1026 ms)
15b)In Unix/Linux file systems, both hard links and symbolic (soft) links allow a file to be accessed through multiple names.
👉 Explain the conceptual difference between them.
✅ Core Idea
-
Hard link → another name for the same file (same inode)
-
Symbolic link (symlink) → a separate file that points to a pathname
🔍 Detailed Comparison
🔹 1. Internal Representation
| Feature | Hard Link | Symbolic Link |
|---|
| Points to | Same inode | Pathname of file |
| Nature | Same file, different name | Separate file |
👉 Hard links are indistinguishable from the original file
👉 Symlinks are like shortcuts
🔹 2. Dependency on Original File
-
Hard link:
-
File exists as long as at least one link exists
-
Deleting original name does NOT delete data
-
Symbolic link:
-
If original file is deleted → becomes dangling link
🔹 3. Storage Behavior
-
Hard link:
-
No extra storage (just directory entry)
-
Symbolic link:
-
Stores path of target file
🔹 4. Access Behavior
-
Hard link:
-
Direct access → no indirection
-
Symbolic link:
-
OS must resolve path → extra lookup
🧩 Example (Linux Commands)
📊 Summary Table
| Aspect` | Hard Link | Symbolic Link |
|---|
| Type | Same file | Pointer file |
| Inode | Same | Different |
| Survives deletion of original | ✔️ Yes | ❌ No |
| Cross filesystem | ❌ No | ✔️ Yes |
| Directory linking | ❌ No | ✔️ Yes |
| Overhead | Low | Slightly higher |
16a)A disk uses fixed sectors of 512 bytes and has 96 sectors per track. The disk rotates at 360 rpm. A processor reads one sector from the disk using interrupt-driven I/O, where one interrupt is generated for each byte transferred. The processor requires 2.5 μs to service each interrupt. Assume that the desired sector is equally likely to be anywhere on the track when the read request is issued. Ignoring seek time, determine the percentage of the total time for this I/O operation during which the processor is busy servicing interrupts.
Given
-
Sector size = 512 bytes
-
Sectors per track = 96
-
Rotation speed = 360 RPM
-
Interrupt per byte
-
Interrupt service time = 2.5 μs per byte
-
Ignore seek time
-
Sector location is random
👉 Find: % of total I/O time CPU is busy handling interrupts
🔹 Step 1: Disk Rotation Time
🔹 Step 2: Average Rotational Latency
Since sector is random:
🔹 Step 3: Transfer Time for One Sector
-
1 track = 96 sectors
-
Time per sector:
🔹 Step 4: Total I/O Time
🔹 Step 5: CPU Time for Interrupts
-
512 bytes → 512 interrupts
-
Each interrupt = 2.5 μs
🔹 Step 6: Percentage CPU Busy
🎯 Final Answer
👉 Processor busy ≈ 1.5% of total I/O time
📊 Summary
| Component | Time |
|---|
| Rotational latency | 83.3 ms |
| Transfer time | 1.736 ms |
| CPU interrupt time | 1.28 ms |
| CPU utilization | ~1.5% |
16b)Consider a file system that uses inodes to represent files. Disk blocks are 4 KB in size, and a pointer to a disk block requires 8 bytes. Each inode contains 10 direct block pointers, two single-indirect pointers, and three double-indirect pointers. Determine the maximum file size that can be supported by this file system. Show your calculations clearly.
Given
-
Block size = 4 KB = 4096 bytes
-
Pointer size = 8 bytes
-
Inode contains:
-
10 direct pointers
-
2 single-indirect pointers
-
3 double-indirect pointers
👉 Find the maximum file size
🔹 Step 1: Pointers per Block
🔹 Step 2: Contribution of Each Type
✅ (a) Direct Blocks
✅ (b) Single Indirect Blocks
Each single-indirect pointer:
-
Points to 1 block containing 512 pointers
-
Each pointer → 1 data block
So:
For 2 such pointers:
✅ (c) Double Indirect Blocks
Each double-indirect pointer:
-
First level: 512 pointers
-
Each points to a block with 512 pointers
For 3 such pointers:
🔹 Step 3: Total Blocks
🔹 Step 4: Total File Size
🎯 Final Answer
👉 Maximum file size ≈ 3.0 GB
📊 Summary
| Type | Blocks | Size |
|---|
| Direct | 10 | 40 KB |
| Single indirect | 1024 | 4 MB |
| Double indirect | 786,432 | ~3 GB |
| Total | 787,466 | ≈ 3.0 GB |
Comments
Post a Comment