You are on page 1of 2

Independent University, Bangladesh

CSE 315 (Operating System)


Midterm Spring 2022
Total: 20 Duration: 1 hour 30 minutes
Write your NAME & ID at each page of your answer. Upload ONE PDF FILE for all of your 4 answers.

1. The following program consists of 3 concurrent processes and 3 binary semaphores. The wait() is the
standard p() operation and release() is the standard v() operation in semaphores. The semaphores are
initialized as S0 = 1, S1 = 0 and S2 = 0.

Process P0 Process P1 Process P2

while (true) {
wait (S0);
print ‘0’; wait (S1); wait (S2);
print ‘0’; print ‘0’;
release (S0); release (S0);
release (S1);
release (S2); }

How many times ‘0’ will be printed? Justifyyour answer.

2. Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T
which are initialized with 1 and 0 respectively. The wait() is the standard p() operation and release() is
the standard v() operation in semaphores. The code for the processes P and Q is shown below:
Process P: Process Q:

while(1) { while(1) {
Wait( A ); Wait( B ):
print '0'; print '1';
print '0'; print '1';
Release( C ) : Release( D ):
} }

We need to get an output string with ‘001100110011’. Assume after printing desired output both
processes forcibly terminated. Which semaphores should be placed in the place of A , B , C & D
?Justify your answer.
3. Consider the set of 3 processes whose arrival time and burst time are given below:

Burst Time
Arrival
Process No. Priority
Time CPU Burst I/O Burst CPU Burst

P1 0 2 1 5 3

P2 2 3 3 3 1

P3 3 1 2 3 1

If the CPU scheduling policy is Priority Scheduling, calculate the average waiting time and average
turn around time. (Lower number means higher priority)

4. Assume there are ‘n’ computers and 1 printer. ‘n’ computers are running a process called ‘data’
which send a file generated by any computer to printer, and the printer is running another process
called ‘print’ which prints the data file send by ‘data’ process in sequence. Both ‘data’ and ‘print’ are
running concurrently. Consider the following situations,
Maximum 3 printing requests can be placed at a time by the process ‘data’. each can hold one item
Semaphore mutex initialized to the value 1
Semaphore full counts number of occupied slots of request queue which is initialized to the value 0
Semaphore empty counts free slots of the queue which has been initialized to the value 3

The structure of ‘data’ process is like the The structure of ‘print’ process is like the
following: following:
do { do {
wait(empty); wait(full);
wait(mutex); wait(mutex);

Generate_Print_Request ( ); Print_Data ( );

signal(mutex); signal(mutex);
signal(full); signal(empty);

} while (true); } while (true);

Suppose sequence of calling data and print process is like following:


data ( );
data ( );
print ( );
print ( );
data ( );
Question: Write down the changes of the values of mutex, full and empty semaphores.

You might also like