0% found this document useful (0 votes)
23 views

Assignment-1

The document outlines an assignment for an Operating Systems course, detailing various questions related to concepts such as race conditions, resource allocation graphs, scheduling algorithms, and synchronization problems. It includes tasks requiring simulations, calculations, and programming examples in C. The assignment covers a wide range of topics, including the Banker’s algorithm, the Sleeping-Barber problem, and the Reader-Writer problem, with specific instructions for each question.

Uploaded by

megav369
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Assignment-1

The document outlines an assignment for an Operating Systems course, detailing various questions related to concepts such as race conditions, resource allocation graphs, scheduling algorithms, and synchronization problems. It includes tasks requiring simulations, calculations, and programming examples in C. The assignment covers a wide range of topics, including the Banker’s algorithm, the Sleeping-Barber problem, and the Reader-Writer problem, with specific instructions for each question.

Uploaded by

megav369
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computer Science and Engineering

School of Computing & Information Technology

Operating System
Assignment-1
Deadline: 14-03-2025
Q. 1 What is a race condition? Give an example and simulate with C programming code.
Q. 2 Consider the resource allocation graph for set of three processes P1, P2,and P3 and
resources R1 (one instance ), R2( two instances) and R3 (one instance) as given below.
identify whether the system is in safe state or the system is in deadlocked. (mention the
execution sequence).

Q. 3 Consider the following set of processes, with the length of the CPU burst given in
milliseconds:

i. Find out turnaround time for each process using the Non-Pre-emptive Priority
Scheduling (a smaller priority number implies a higher priority)?
ii. Find out turnaround time for each process using Pre-emptive Priority Scheduling
(a smaller priority number implies a higher priority)?
iii. Find out turnaround time for each process using Non-Pre-emptive Shortest Job
First Time?
iv. Find out turnaround time for each processes using Pre-emptive Shortest Job First
Time (or Shortest-Remaining-Time-First)?

Q. 4 Consider three concurrently executing threads in the same process using two
semaphores s1 and s2. Assume s1 has been initialized to 1, while s2 has been initialized to 0.
What are the possible values of the global variable x, initialized to 0, after all three threads
have terminated?
Department of Computer Science and Engineering
School of Computing & Information Technology

/* thread A */
P(&s2);
P(&s1); x = x*2;
V(&s1);

/* thread B */
P(&s1);
x = x*x;
V(&s1);

/* thread C */
P(&s1);
x = x+3;
V(&s2);
V(&s1);

Q. 5 Consider the following code:


int a = 0;
int main() {
fork();
a++;
fork();
a++;
if (fork() == 0)
{
print(“Hello!\n”);
} else {
print(“Goodbye!\n”);
}
a++;
print(“a is %d\n”, a);
}

Q. 6 What could the output of the concurrent execution of process A and process B be? (State
all possible outputs).

int x=0;
int y=0; “initialization”

Process A Process B
while(x==0) {do-nothing}; printf(“b”);
printf(“a”); x=1;
y=1; while(y==0) {do-nothing};
y=0; printf(“c”);
Department of Computer Science and Engineering
School of Computing & Information Technology

printf(“d”);
y=1;

Q. 7 A resource allocation system that uses the Banker’s algorithm for 3 resource types (A,
B, C) and 5 users (P0, P1, P2, P3 P4) is currently in the following state. (Alloc: resources
held by each user. Max: max need of each user. Req: ongoing request of each user. Avail:
free resources.)
Allocation Max Req. Avail
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 2 2 3 3 2
P1 2 0 0 3 2 2 0 2 1
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 0
P4 0 0 2 4 3 3 2 3 0
i. What is the content in need matrix.
ii. Is the state safe. If you answer yes, give a sequence of process ids that leads to all
processes completed. If you answer no, give a sequence of activities that results in
a deadlocked state.

Q. 8 Write the syntax and explain the use of following system calls:
Fork, exec, wait, exit, read, write, open, dup, dup2.

Q. 9 We are given a multilevel feedback queue scheduling system, where:


● The first queue has a time quantum (TQ) of 2 seconds.
● At each lower queue, the time quantum increases by 5 seconds.
● The process is totally CPU-bound and requires 40 seconds to complete execution.
We need to determine:
i. How many times the job will be interrupted?
ii. On which queue the job will terminate?

Q. 10 The Sleeping-Barber Problem:- There is a barber shop with one barber and a number of
chairs for waiting customers. Customers arrive at random times and if there is an available
chair, they take a seat and wait for the barber to become available. If there are no chairs
available, the customer leaves. When the barber finishes with a customer, he checks if there
are any waiting customers. If there are, he begins cutting the hair of the next customer in the
queue. If there are no customers waiting, he goes to sleep.
The problem is to write a program that coordinates the actions of the customers and the
barber in a way that avoids synchronization problems, such as deadlock or starvation.
Department of Computer Science and Engineering
School of Computing & Information Technology

Q. 11 A system has four processes and five allocatable resources. The current allocation and
maximum needs are as follows:
Allocated Maximum Available
Process A 10211 11212 00x11
Process B 20110 22210
Process C 11010 21310
Process D 11110 11221

What is the smallest value of x for which this is a safe state?

Q. 12 Consider the following snapshot of a system:


Allocation Maximum Available
A B C D A B C D A B C D
P1 0 0 1 2 0 0 1 2 1 5 2 0
P2 1 0 0 0 1 7 5 0
P3 1 3 5 4 2 3 5 6
P4 0 6 3 2 0 6 5 2
P5 0 0 1 4 0 6 5 6

Q. 13 Two processes, A and B, each need three records, 1, 2. And 3, in a database. If A asks
for them in the order 1, 2, 3, and B asks for them in the same order, deadlock is not possible.
However, if B asks for them in the order 3, 2, 1, then deadlock is possible. With three
resources, there are 3! or 6 possible combinations each process can request the resources.
What fraction of all the combinations is guaranteed to be deadlock free?

Q. 14 The Cigarette-Smokers Problem. Consider a system with three smoker processes and
one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll
and smoke a cigarette, the smoker needs three ingredients: tobacco, paper, and matches. One
of the smoker processes has paper, another has tobacco, and the third has matches. The agent
has an infinite supply of all three materials. The agent places two of the ingredients on the
table. The smoker who has the remaining ingredient then makes and smokes a cigarette,
signaling the agent on completion. The agent then puts out another two of the three
ingredients, and the cycle repeats. Write a program to synchronize the agent and the smokers.

Q. 15 The Reader-Writer Problem is a classic synchronization problem where multiple


processes (readers and writers) access a shared resource. In the traditional Reader-Writer
model, multiple readers can access the resource simultaneously, but writers need exclusive
access.
However, in real-world applications like databases, file systems, and cloud storage, multiple
writers often need to update the resource concurrently. This introduces challenges such as
mutual exclusion, starvation, and fairness between readers and writers.
Assignment Task:
1. Explain the Reader-Writer Problem, its significance, and the challenges of allowing
multiple writers.
2. Describe different synchronization techniques (e.g., semaphores, mutexes, monitors)
used to handle multiple readers and writers efficiently.
Department of Computer Science and Engineering
School of Computing & Information Technology

3. Propose a pseudocode solution or flowchart for a system that allows both multiple
readers and multiple writers while ensuring fairness.
4. Discuss real-world applications where this problem occurs and how modern systems
(such as databases) handle concurrent read and write operations.
5. Explain starvation in the Reader-Writer Problem and propose methods to prevent
starvation for both readers and writers.

You might also like