CS-20002 (Os) - CS Mid Feb 2025
CS-20002 (Os) - CS Mid Feb 2025
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)
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.
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.