0% found this document useful (0 votes)
9 views8 pages

CS-20002 (Os) - CS Mid Feb 2025

The document discusses various concepts in operating systems, including scheduling algorithms, semaphore usage, process states, and deadlock conditions. It provides detailed explanations and examples for Shortest Job First scheduling, binary semaphores, the producer-consumer problem, and the necessary conditions for deadlock. Additionally, it covers the differences between independent and cooperating processes, as well as race conditions.

Uploaded by

aishjoshi0117
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)
9 views8 pages

CS-20002 (Os) - CS Mid Feb 2025

The document discusses various concepts in operating systems, including scheduling algorithms, semaphore usage, process states, and deadlock conditions. It provides detailed explanations and examples for Shortest Job First scheduling, binary semaphores, the producer-consumer problem, and the necessary conditions for deadlock. Additionally, it covers the differences between independent and cooperating processes, as well as race conditions.

Uploaded by

aishjoshi0117
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/ 8

1 a): NOTE: 1 mark for answer with solution and 0.

5 mark for correct answer without


solution.
Since the scheduler has prior knowledge of CPU bursts, the optimal scheduling
algorithm to minimize average waiting time is Shortest Job First (SJF) (Non-
Preemptive).
Process CPU Burst (ms)
P3 10
P1 16
P2 20
P3 starts at t = 0 and completes at t = 10
P1 starts at t = 10 and completes at t = 26
P2 starts at t = 26 and completes at t = 46
Burst Waiting Time
Arrival Completion Turnaround Time
Process Time (WT) = TAT -
Time (AT) Time (CT) (TAT) = CT - AT
(BT) BT
P3 0 10 10 10 0
P1 0 16 26 26 10
P2 0 20 46 46 26
Thus, the minimum achievable average waiting time is (0 + 10 + 26) / 3 which is 12
milliseconds.

1 b): NOTE: 1 mark for answer with solution and 0.5 mark for correct answer
without solution.
Binary semaphore which can take only two values 0 and 1 and ensure mutual
exclusion. A process is entered into the critical section only when the value of
semaphore(s) = 1, Otherwise, it will wait until semaphore(s) >0.
The semaphores are initialized as S0=1, S1=0, S2=0.
Because S0 =1 then P0 enter into the critical section and other processes will wait
until either S1=1 or S2 =1.
The minimum number of times 0 printed:
S0 =1 then P0 enter into the critical section
print '0'
then release S1 and S2 means S1 =1 and s2 =1
now either P1 or P2 can enter into the critical section
if P1 enter into the critical section
release S0
then P2 enter into the critical section
release S0
P1 enter into the critical section
print '0'
The minimum number of time 0 printed is twice when executing in this order (p0 ->
p1 -> p2 -> p0)

The Maximum number of times 0 printed:


S0 =1 then P0 enter into the critical section
print '0'
Then release S1 and S2 means S1 =1 and s2 =1
Now either P1 or P2 can enter into the critical section
If P1 enter into the critical section
Release S0 means S0 =1
S0 =1 then P0 enter into the critical section
print '0'
Then P2 enter into the critical section
Release S0 means S0 =1
S0 =1 then P0 enter into the critical section
print '0'
Maximum no. of time 0 printed is thrice when execute in this order (p0 -> p1 -> p0 ->
p2 -> p0)

So, At least twice will process P0 print ‘0’. Hence, the correct answer is option a).

1c): NOTE: 1 mark for answer with solution and 0.5 mark for correct answer without
solution.
When the value of 'i' is even then fork() statement is executed.
(1) when i = 0, then fork() will executed.
(2) when i = 2, then fork() will executed.
(3) when i = 4, then fork() will executed.
(4) when i = 6, then fork() will executed.
(5) when i = 8, then fork() will executed.
So total 5 times fork() will executed.
We know, n - fork statements will create 2n - 1 childs.
5 fork statements will create 25 - 1 = 31 childs.

1d): NOTE: 1 mark for answer with explanation and 0.5 mark for correct answer
without explanation.
The solution cannot be considered as a valid one because it only achieves mutual
exclusion and bounded waiting. It is not achieveing progress, which is a mandatory
criteria (along with mutual exclusion) to a solution for the critical section problem.

1e): NOTE: 1 mark for answer with explanation and 0.5 mark for correct answer
without explanation.
In worst case,
The number of units that each process holds = One less than its maximum demand
So,
Process P1 holds 20 units of resource R
Process P2 holds 30 units of resource R
Process P3 holds 40 units of resource R
Thus,
Maximum number of units of resource R that ensures deadlock = 20 + 30 + 40 = 90
Minimum number of units of resource R that ensures no deadlock = 90 + 1 = 91.

Ans 2 (i): NOTE: 1 mark for diagram and 2 marks for explanation:
The 5-State Model of a process:
The states present in the 5-state model are as follows −
New − When a new process is created, It enter into the new state. Then it tries to load
into RAM.
Ready − The processes that are loaded on RAM and waiting for CPU are in ready
state.
Running − The processes that are running on the CPU are in running state.
Blocked − All processes that are leaving the CPU and moving to the waiting state are
in the blocked state. When the CPU becomes free, processes from the blocked state
again move to the ready state, and from ready to Running state.
Exit / Terminated − A process that is terminated from CPU and RAM is in the
terminated state.

Ans 2 (ii): NOTE: 1 mark for difference between independent process and
cooperating process and 1 mark for definition of race condition.
Independent Vs. cooperating process:
An independent process is one that does not affect or is not affected by other
processes running on the system, meaning it operates completely on its own without
sharing data or resources with any other process, while a cooperating process is one
that can influence or be influenced by other processes, typically by sharing data or
resources, requiring mechanisms like inter-process communication (IPC) to
coordinate their actions.
Race condition: A race condition is an undesirable situation that occurs when a
device or system attempts to perform two or more operations at the same time, but
because of the nature of the device or system, the operations must be done in the
proper sequence to be done correctly.

Ans 3 (i): NOTE: 3 marks for correct explanation:


Producer - Consumer Problem:
We need to ensure that when a producer is placing an item in the buffer, then at the
same time consumer should not consume any item and vice versa.
Problem Statement –
 We have a buffer of fixed size.
 A producer can produce an item and can place in the buffer.
 A consumer can pick items and can consume them.
 We need to ensure that when a producer is placing an item in the buffer, then at
the same time consumer should not consume any item and vice versa.
 In this problem, buffer is the critical section.
Solution using semaphores:

Three semaphores are used here:


Semaphore S = 1, this semaphore is used to handle CS
Semaphore E = n, where E stands for empty slots. Initially, all the slots are empty, so
E is initialized by n (where n is the total size of the buffer).
Consider n = 5, as an example, therefore, here E will be initialized with the value 5.
Semaphore F = 0, It will check how many slots are full.

Checking whether if producer is active (i.e., it is using the buffer), then, whether
the consumer can become active or not:
For producer to be active, it will do the following:
1. Produce an item using, produce(),
2. It will perform wait on E, therefore, E = 4.
3. It will perform wait on S, therefore, S = 0.
4. It will append the item produced in Step-1 using append(). Now suppose at this
time consumer becomes active, then it will perform wait on F which is not possible
because currently F = 0. Therefore, consumer cannot proceed and becomes inactive.
5. Producer will perform signal on S, hence, S = 1.
6. Producer will perform signal on F, hence, F = 1.

In the same way, we can check if consumer is active (i.e., it is using the buffer),
then, whether the producer can become active or not.

Ans 3 (ii): NOTE: 0.5 mark for only naming the four necessary conditions and 1.5
mark for explanation:
Necessary Conditions for Deadlock:
A deadlock situation can arise if the following four conditions hold simultaneously in
a system:
1. Mutual exclusion: A resource can only be shared in mutually exclusive manner. It
implies that two processes cannot use the same resource at the same time.
2. Hold and wait: A process waits for some resources while holding another resource
at the same time.
3. No preemption: Resources cannot be preempted; that is, a resource can be released
only by the process holding it, after that process has completed its task.
4. Circular wait: All the processes must be waiting for the resources in a cyclic
manner so that the last process is waiting for the resource which is being held by the
first process.

Ans 4: NOTE: 2 Marks for Gantt chart only. 5 Marks for entire correct solution.
Solution prepared by Director sir:
Ans 5: NOTE: 2 Marks for the explanation for the components of RAG. 3 Marks for
obtaining the safe sequence.

OR
NOTE: Solution to this question may have more safe sequences.

You might also like