You are on page 1of 3

Operating System (CS604) Total marks = 20

Assignment # 02 Deadline Date

MC180405989 December 16, 2020

Question No.1
Considering the two processes SP (Server Process) and CP Client Process, each creates two
child process sc1, sc2, and cc1, cc2, respectively. These processes create two FIFOs, FIFO 1
for reading and FIFO 2 for writing in SP and FIFO 1 for writing and FIFO2 for reading in CP to
communicate with each other as shown in the figure.

Figure 1. Client-Server Communication

By considering the above scenario, you are required to write the output of the following
code snippets.

1. if ((mknod (FIFO1, S_IFIFO | PERMS, 0) < 0) && (errno != EEXIST))


{
perror ("mknod FIFO1");
exit (1);
}
2. if (mkfifo(FIFO2, PERMS) < 0)
{
unlink (FIFO1);
perror("mknod FIFO2");
exit (1);
3. if ((readfd = open(FIFO1, 0)) < 0)
{
perror ("open FIFO1");
exit (1);
4. if ((writefd = open(FIFO2, 1)) < 0)
{
perror ("open FIFO2");
exit (1);
5. size = strlen(MESSAGE1) + 1;
if ((n = read(readfd, buff, size)) < 0) {
perror ("server read"); exit (1);
}
6. size = strlen(MESSAGE1) + 1;
if (write(writefd, MESSAGE1, size) != size)
{ perror ("client write1"); exit (1);
}

Solution:

Output=server read
Client write 1

Question No. 2
Consider the following set of processes, with the Arrival time and CPU burst time, is given in
milliseconds:
Process Arrival Time Burst Time
P1 0.0 10
P2 2.0 6
P3 3.0 2
Considering the time slice of 4 milliseconds.
A. Draw a Gantt chart showing the execution of these processes using the Shortest
Remaining Time First (SRTF) scheduling.

Solution:

P1 P1 P2 P3 P3 P2 P1
1 1 2 3 4 5 10 18

B. Calculate the turnaround time of each process for the Shortest Remaining Time First
scheduling algorithm as per part Calculation of part A?
Solution:
Process Arrival Time Burst Time
P1 0.0 10
P2 2.0 6
P3 3.0 2
Completion time of processes:
P1 = 18
P2 = 10
P3 = 15
Turnaround Time:
Turnaround Time (TAT) = Completion Time – Arrival Time
TAT of P1 = 18-0.0
= 18
TAT of P2 = 10-2.0
=8
TAT of P3 = 5-3.0
=2

C. Calculate the waiting time of each process for the SRTF scheduling algorithm as per
the calculation of Part A?
Solution:
Process Arrival Time Burst Time
P1 0.0 10
P2 2.0 6
P3 3.0 2
Waiting Time:
Waiting Time (WT) = Turnaround Time – Burst Time
WT of P1 = 18-10
=8
WT of P2 = 8-6
=2
WT of P3 = 2-2
=0

You might also like