Mid Term - CS F 372 - Operating Systems

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1

Birla Institute of Technology and Science, Pilani - K.K. Birla


Goa Campus
CS F372 MidTerm Test 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.) . Explain your answer. [10 Marks]

#include <sys/types.h> pid1 = getpid();


#include <stdio.h> printf("child: pid = %d",pid); /* A */
#include <unistd.h> printf("child: pid1 = %d",pid1); /* B */
int main() }
{ else { /* parent process */
pid t pid, pid1; pid1 = getpid();
pid = fork(); printf("parent: pid = %d",pid); /* C */
if (pid < 0) { printf("parent: pid1 = %d",pid1); /* D */
fprintf(stderr, "Fork Failed"); wait(NULL);
return 1; }
} return 0;
else if (pid == 0) { }

Q2. The program shown in below uses the Pthreads API. What would be the output from the program at LINE
C and LINE P? Explain your answer. [10 Marks]

#include <pthread.h> pthread join(tid,NULL);


#include <stdio.h> printf("CHILD: value = %d",value); /*
#include <types.h> LINE C */
int value = 0; }
void *runner(void *param); /* the thread */ else if (pid > 0) { /* parent process */
int main(int argc, char *argv[]) wait(NULL);
{ printf("PARENT: value = %d",value); /*
pid t pid; LINE P */
pthread t tid; }
pthread attr t attr; }
pid = fork(); void *runner(void *param) {
if (pid == 0) { /* child process */ value = 5;
pthread attr init(&attr); pthread exit(0);
pthread create(&tid,&attr,runner,NULL); }

Q3. Write a Socket-based 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. 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)
2

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) [18 Marks]
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.

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. Explain your answer. [ 12 Marks]

Q5. 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

Q6. 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. [10 Marks]
Using Banker’s algorithm
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.

Process MAX ALLOCATION


A B C D A B C D
P0 0 0 1 2 0 0 1 2
P1 1 7 5 0 1 0 0 0
P2 2 3 5 6 1 3 5 4
P3 3 6 5 2 0 6 3 2
P4 0 6 5 7 0 0 1 0

---xxx---

You might also like