Mid Sem - CSF 372 - Operating Systems - Solutions
Mid Sem - CSF 372 - Operating Systems - Solutions
Birla Institute of Technology and Science, Pilani - K.K. Birla Goa Campus
CS F372 Test-I Max. Marks Date Time
Operating Semester-I (Closed Book) = 90 13-10-2017 4:00 - 5:30 PM
Systems
Q1. Using the program in below, identify the values of pid at lines A, B, C, and D. (Assume that the actual pids of the
parent and child are 2600 and 2603, respectively.) [10]
Solutions: For reference, the solutions are 0, 2603, 2603, and 2600.
Q2. The program shown in below uses the Pthreads API. What would be the output from the program at LINE C and
LINE P? [10]
Solutions:
Line C: CHILD: value = 5 since the thread changes the value of the global variable.
Line P: PARENT: value = 0 no change to the global variable is made in the parent,
changes made in the child process does not affect
the global variables in the parent process.
Q3. Java Program to Send a Message from Client to Server and Receive a Response Back Using Socket
Programming
What this program does?
This Java Program
1. Make Use of Java Socket Programming
2
2. It starts a server which will be always running listening to a port 25000 (Server.java)
3. Client (Client.java) sends a number (message) to the server
4. Server receives this number and multiplies it by 2
5. Server (Server.java) sends back the result (message) to the client (Client.java)
6. In case the number sent by the client was not a proper number, server (Server.java) sends back the message
“Please send a proper number” to the client (Client.java)
Note: Please run Server.java because server should be ready before client sends the message to it.
[10]
Solutions:
Server.Java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
Clint. Java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
Q4. The following state transition table is a simplified model of process management, with the labels representing
transitions between states of READY, RUN, BLOCKED, and NONRESIDENT. [10]
Give an example of an event that can cause each of the above transitions, namely 1, 2, 3, 4, 5 and 6. Draw a State
Transition Diagram (STD) for each example.
5
Answer:
1. READY to RUN occurs only if a process is allocated the CPU. This is the job of the scheduler or dispatcher
2. RUN to READY can be caused by a time-quantum expiration (running process has reached the maximum allowable
time for uninterrupted execution).
3. RUN to BLOCKED can occur if there is a request from the operating systems process, or I/O or other kernel request.
4. BLOCKED to READY occurs if the awaited event completes the event it is been waiting for (perhaps I/O completion).
5. READY to NONRESIDENT occurs if memory is overcommitted, and a process is temporarily swapped out of memory.
6. BLOCKED to NONRESIDENT - occurs if memory is overcommitted, and a process is temporarily swapped out of
memory same just as ready to nonresident
[10 Marks]
Q6. Consider 4 processes A, B, C and D in a Uniprocessor system. xPy represents process P goes for x units of I/O
operation after y units of execution. Arrival time, execution time and xPy of all processes are given in table below.
Consider time quantum of 4 units. [20 Marks]
a. Draw the resultant schedule and queues using Virtual Round Robin scheduling algorithm.
b. Find the waiting period of A and B processes.
c. Find the Turnaround Time of C and D processes.
d. List the time units when the process is preempted and find the number of preemptions.
Process Arrival Time Execution Time xPy
A 0 8 2A6
B 2 5 5B2
C 3 5 CPU bound
D 6 7 4D4
Q7. Consider the following snapshot of the system with five processes P0 toP4 and 4 resource types A, B, C and D with
instances 3, 14, 12 and 8 respectively.
Using Banker’s algorithm
6
a. Check whether the system is safe or not. If the system is safe give a safe sequence. If not, name all the processes
in unsafe state.
b. If a request from P1 arrives (0,4,2,0) can the request be granted? Give reasons.