0% found this document useful (0 votes)
38 views9 pages

Assignment 2

The document outlines an assignment for the Operating System course at MIT School of Computing, Pune, detailing various problems related to process synchronization, race conditions, deadlock detection, and resource allocation. Each question requires analysis and application of concepts such as semaphores, critical sections, and the Banker’s Algorithm. The assignment aims to assess students' understanding and ability to solve complex problems in operating systems.

Uploaded by

xhv2j4y6qz
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)
38 views9 pages

Assignment 2

The document outlines an assignment for the Operating System course at MIT School of Computing, Pune, detailing various problems related to process synchronization, race conditions, deadlock detection, and resource allocation. Each question requires analysis and application of concepts such as semaphores, critical sections, and the Banker’s Algorithm. The assignment aims to assess students' understanding and ability to solve complex problems in operating systems.

Uploaded by

xhv2j4y6qz
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

MIT Art Design and Technology University, Pune

MIT School of Computing, Pune

Department of Computer Science and Engineering

Assignment II
Subject- Operating System

Course Outcome: CO3 Academic Year:2024-25

Sr. Bloom's
No. Question Level

Race Condition (Numerical Analysis)


A shared variable X = 10 is accessed by two concurrent processes P1 and P2:
P1 executes: P2 executes:
LOAD R1, X LOAD R2, X
Analyzing
1 ADD R1, 5 SUB R2, 3
(BL4)
STORE R1, X STORE R2, X

If both processes execute concurrently in an arbitrary interleaving, what are the


possible final values of X? Show all interleaved execution sequences and justify your
answer

Semaphore Synchronization (Buffer Problem)


A bounded buffer has 5 slots, and it is controlled using:
• Mutex (M) (binary semaphore) for mutual exclusion.
Applying
• Full (F) (counting semaphore) initialized to 0. (BL3) /
2
Analyzing
• Empty (E) (counting semaphore) initialized to 5.
(BL4)
At time t = 0, the buffer is empty. The producer starts producing 1 item every second,
while the consumer starts removing 1 item every 2 seconds.
1. Calculate the buffer occupancy at t = 10 seconds.
2. If two producers work at the same rate, what will be the buffer state at t = 10
seconds?
3. Justify whether a deadlock can occur.

Two processes P1 and P2 use Peterson’s Solution to achieve mutual exclusion.


• P1’s critical section execution time = 3 ms
• P2’s critical section execution time = 5 ms Applying
(BL3) /
3 • The system is preemptive, and the time slice is 10 ms. Analyzing
1. Calculate how long P1 and P2 will take to complete 5 critical section (BL4)
executions each.
2. Justify if starvation can occur if a high-priority process is introduced.

A buffer has 6 slots. The producer and consumer follow the semaphore mechanism,
where:
• Producer takes 2 seconds to produce 1 item.
Applying
• Consumer takes 3 seconds to consume 1 item. (BL3) /
4
At t = 0, the buffer is empty. Analyzing
(BL4)
1. Compute the buffer occupancy at t = 12 seconds.
2. If a consumer speedup mechanism is introduced, how should the buffer size
be modified to avoid underflow?

A system consists of 3 processes (P1, P2, P3) and 3 resource types (R1, R2, R3).
Current Allocation & Need:

Process Allocation (R1, R2, Maximum Need (R1, R2, Available (R1, R2,
R3) R3) R3)

P1 (1, 1, 0) (3, 2, 2) (1, 1, 1)


Analyzing
5
P2 (0, 1, 1) (2, 2, 2) (BL4)

P3 (1, 0, 1) (2, 1, 1)

Using Banker’s Algorithm, determine:


1. If the system is in a safe state.
2. If not, identify the deadlocked processes and justify your reasoning.
A system has 4 processes (P1, P2, P3, P4) and 4 resource types (R1, R2, R3, R4).
Each process requests one resource at a time in the following sequence:
• P1 → R1 → R2
Analyzing
• P2 → R2 → R3 (BL4) /
6
Creating
• P3 → R3 → R4
(BL6)
• P4 → R4 → R1
1. Construct the Resource Allocation Graph (RAG) and determine if a circular
wait exists. Suggest an order of resource allocation to prevent deadlock.

A system has 5 processes (P1-P5) and 3 resource types (R1, R2, R3).
• P1 holds (1, 2, 1) and requests (1, 0, 1).
• P2 holds (2, 0, 1) and requests (0, 1, 1). Analyzing
(BL4) /
7 • P3 holds (1, 1, 0) and requests (1, 1, 1).
Creating
The available resources are (1, 1, 1). (BL6)
1. Check if any process can complete safely.
Suggest a resource allocation order to prevent deadlock

A client-server model uses message passing for communication.


• Message size: 4 KB
• Network latency: 10 ms
• Transmission speed: 1 MBps Applying
• Processing delay: 5 ms (BL3) /
8
Evaluating
1. Calculate the total time to send a message from the client to the server and (BL5)
receive a response.
2. If the message size is increased to 8 KB, how does the transmission delay
change?
3. Justify whether shared memory would be a better alternative.

A barber shop operates as follows: Applying


(BL3) /
9 • One barber
Evaluating
• 5 waiting chairs (BL5)
• Customers arrive every 3 minutes
• Haircut takes 7 minutes
1. Calculate how many customers will be waiting at t = 20 minutes.
2. If a second barber is added, compute the new average waiting time per
customer.
Justify whether the shop should increase or decrease chairs.

A multi-threaded system has 3 cooperating processes (P1, P2, P3) sharing resources.
• P1 execution time: 10 ms
• P2 execution time: 15 ms
• P3 execution time: 20 ms Applying
(BL3) /
10 • Synchronization overhead per process switch: 2 ms
Evaluating
The processes execute in a cyclic order (P1 → P2 → P3 → P1 …). (BL5)
1. Compute the total execution time for 2 full cycles.
2. If synchronization overhead is reduced to 1 ms, recalculate execution time.
3. Justify whether an asynchronous approach would improve performance.

Process Synchronization: Race Condition ProbabilityA shared counter is incremented


by two threads, each 100 times without synchronization. Each increment involves 3 Applying
11
operations (read, modify, write). Due to interleaving, some increments may be lost. (BL3)
Calculate the possible range of final counter values.

Critical-Section Execution Time A system has 5 processes executing in a critical


Applying
12 section. Each process spends 10ms in the critical section. The scheduler uses Peterson’s
(BL3)
algorithm for synchronization. Compute the total execution time for all processes.

Semaphore-Based Process Coordination Semaphore S controls access to a shared


Applying
13 resource. Initial value of S = 3. 10 processes request access randomly. Calculate the
(BL3)
maximum processes that can be in the critical section simultaneously.

Applying
A system has 5 philosophers and 5 chopsticks. Each philosopher spends 40% time
(BL3) /
14 eating and 60% thinking. A mutex-based solution ensures no two neighbours eat
Analyzing
simultaneously. Compute maximum chopstick utilization at a given time.
(BL4)

A database allows 10 readers and 5 writers. A reader takes 5ms to read. A writer takes Applying
15
10ms to write. Compute average read time per second assuming fair scheduling. (BL3) /
Analyzing
(BL4)

A system has 3 processes (P1, P2, P3) and 2 resource types (R1, R2). The allocation Analyzing
16
and request matrices are provided. Determine if a deadlock exists. (BL4)

IPC Message Passing LatencyA client-server system sends 10 messages per second. Applying
17
Each message takes 5ms to process. Compute total system latency per second. (BL3)

Applying
A barber shop has 3 chairs and customers arrive every 5 minutes. The barber takes 10 (BL3) /
18
minutes per haircut. Calculate the average number of customers waiting. Analyzing
(BL4)

A Banker’s Algorithm system has: Total resources: 10, Allocated: 6, Maximum needed: Applying
19
9. Compute minimum additional resources required to avoid deadlock. (BL3)

A deadlock detection system runs every 30 seconds. Each process takes 10ms to restart. Applying
20
Compute total recovery time if 5 processes are in deadlock. (BL3)

Understanding
A banking system has two threads that access the same account balance. One thread
(BL2) /
21 withdraws ₹5,000 while the other checks if the balance is sufficient. Explain how a
Applying
race condition might occur and how to resolve it.
(BL3)

Two threads (T1 and T2) access a shared variable. If T1 enters the critical section first, Understanding
22
explain how Peterson’s solution ensures T2 waits. (BL2)

A bakery produces and sells cakes using a buffer of size 5. If the baker (producer)
Analyzing
23 makes a cake every 3 minutes and a customer (consumer) buys one every 5 minutes,
(BL4)
analyze the buffer's state over time.

A university library has a digital book that can be read by multiple users but edited by Applying
24
only one librarian. Model this situation using semaphores. (BL3)

Understanding
Two processes, P1 and P2, exchange messages over a network. If P1 sends a message (BL2) /
25
before P2 is ready, what problems might arise? Suggest a solution. Applying
(BL3)

Applying
Two processes (P1 and P2) wait for each other’s message to proceed, causing a (BL3) /
26
deadlock. Design a timeout mechanism to prevent this. Creating
(BL6)
A railway network has two trains on intersecting tracks. If both need the same track Understanding
27
section and wait for each other to move, explain why this is a deadlock. (BL2)

Peterson’s Solution (Critical Section Execution Time)

Two processes P1 and P2 use Peterson’s Solution for mutual exclusion.

• P1’s critical section execution time = 4 ms


Analyzing
28 • P2’s critical section execution time = 6 ms
(BL4)
• The system is preemptive, and the time slice is 8 ms.

1. Calculate the total time taken for 5 critical section executions per process.

If a high-priority process is introduced, can starvation occur? Justify

Producer-Consumer Problem (Numerical with Synchronization Delay)

A buffer has 8 slots. The producer and consumer operate using semaphores where:

• Producer takes 3 seconds to produce 1 item.


Applying
• Consumer takes 4 seconds to consume 1 item. (BL3) /
29
Analyzing
At t = 0, the buffer has 3 items.
(BL4)
1. Compute the buffer occupancy at t = 15 seconds.

If a producer speedup mechanism is introduced, how should the buffer size be modified
to prevent overflow?

Deadlock Detection (Resource Allocation Graph)

A system has 4 processes (P1, P2, P3, P4) and 3 resource types (R1, R2, R3).
Current Allocation & Need:

Process Allocation (R1, R2, R3) Maximum Need (R1, R2, R3) Available (R1,
R2, R3) Applying
P1 (1, 0, 1) (2, 2, 2) (1, 1, 0) (BL3) /
30
Analyzing
P2 (0, 1, 1) (2, 1, 2) (BL4)
P3 (1, 1, 0) (3, 2, 1)

P4 (0, 0, 1) (1, 1, 2)

Using Banker’s Algorithm, determine:


1. If the system is in a safe state.
2. If not, identify the deadlocked processes.

Deadlock Prevention (Resource Allocation Order)

A system has 6 processes (P1-P6) and 3 resource types (R1, R2, R3).
• P1 holds (2, 1, 1) and requests (1, 0, 1).
Applying
• P2 holds (1, 2, 0) and requests (0, 1, 1). (BL3) /
31
• P3 holds (1, 1, 1) and requests (2, 0, 0). Analyzing
(BL4)
Available resources: (2, 1, 1).

1. Check if any process can be completed safely.

2. Suggest a resource request strategy to avoid deadlock.

IPC Performance Calculation (Message Passing Delay)

A distributed system uses message passing for IPC.


• Message size: 6 KB
Applying
• Network latency: 8 ms (BL3) /
32
• Transmission speed: 2 MBps Analyzing
(BL4)
• Processing delay: 4 ms

1. Calculate the total time to send and receive a response.

2. If message size increases to 12 KB, analyze delay changes.

Sleeping Barber Problem (Queue Analysis)

A barber shop has:

• 1 barber
Analyzing
• 4 waiting chairs (BL4) /
33
• Customers arriving every 4 minutes Creating
(BL6)
• Haircut duration of 6 minutes

1. Calculate how many customers are waiting at t = 24 minutes.

2. If an assistant barber is added, analyze the impact on wait times.

A taxi booking app assigns one driver to a customer. Two customers are assigned the Understand
34
same driver due to improper locking. Suggest a fix (BL1)
Deadlock Avoidance (Circular Wait Condition)

A system with 5 processes (P1-P5) and 5 resource types (R1-R5) has a request
pattern:

• P1 → R1 → R2
Applying
• P2 → R2 → R3
(BL3) /
35
• P3 → R3 → R4 Analyzing
(BL4)
• P4 → R4 → R5

• P5 → R5 → R1

1. Construct a Resource Allocation Graph (RAG) and detect any circular wait.

Suggest an allocation order to avoid deadlock

Semaphore Synchronization (Buffer Problem)

A bounded buffer has 6 slots, controlled by:

• Mutex (M) (binary semaphore) for mutual exclusion.


• Full (F) (counting semaphore) initialized to 0.
Applying
• Empty (E) (counting semaphore) initialized to 6.
(BL3) /
36
At time t = 0, the buffer is half full. The producer adds 1 item per second, while the Analyzing
consumer removes 1 item every 3 seconds. (BL4)

1. Calculate the buffer occupancy at t = 12 seconds.

2. If three consumers start consuming at the same rate, what will be the buffer
state at t = 12 seconds?

3. Justify whether a deadlock can occur.

A shared variable X = 20 is accessed by three concurrent processes P1, P2, and P3:

P1 executes: P2 executes: P3 executes:

LOAD R1, X LOAD R2, X LOAD R3, X Applying


ADD R1, 8 SUB R2, 5 MUL R3, 2 (BL3) /
37
Analyzing
STORE R1, X STORE R2, X STORE R3, X (BL4)

If all processes execute concurrently with arbitrary interleavings, what are the possible
final values of X? Show all interleaved execution sequences and justify your answer
Process Scheduling with Synchronization Overhead

A system has 3 processes (P1, P2, P3) sharing resources.


• P1 execution time: 8 ms

• P2 execution time: 12 ms Analyzing


38
• P3 execution time: 18 ms (BL4)

• Synchronization overhead per switch: 3 ms

1. Compute total execution time for 2 full cycles.

2. If overhead reduces to 1 ms, reanalyze execution time.

Discuss the key challenges in implementing deadlock detection in distributed systems.


39 How do algorithms for detecting and resolving deadlocks differ in centralized and Understand
distributed environments? (BL1)

Compare software-based and hardware-based transactional memory. How do


40 transactional memory mechanisms serve as an alternative to traditional locking Understand
techniques, and what impact do they have on system performance? (BL1)

You might also like