Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Operating System (CS604) Total marks = 20

Assignment # 02 Deadline Date

Spring 2021 03/06/2021

Student ID BC180408636

Question No. 1 15 Marks

Write the two C programs named program1and program2 that perform inter-process
communication through FIFO. The functionality of the two programs should be as follows.
 program1 should create a FIFO as fifo_oneby using mknod()system call or
throughmkfifo() library call. program1 should open the fifo_one for reading purposes
through open() system call. Then use the read() system call to read from fifo_one,
your name, and VUID that is written by program2 in fifo_one. After reading your
name and VUID,program1 should display it on the screen bywrite() system call.
 program2 should open the fifo_one for writing purposes through open() system call.
Then use the write() system call to write in fifo_one your name and VUID. And
finally, close and remove the fifo_one.
Use only read() and write() system call for reading and writing your name and VUID from
FIFO and finally writing on the terminal screen. As by default in FIFO both read() and write()
system call do the blocking I/O.
As the two programs can’t be run simultaneously in the foreground on the terminal window.
So you need to run program1 in the background and subsequently program2 should be run
in the foreground.
Following is the sample screenshot of both programs. You need to perform the following
steps in the screenshot.
 In the screenshot firstly you should compile both C programs.
 Run theprogram1 in the background.finally,
 run the program2.
C code of question no. 1 for both programs should also be pasted in the same word file after
the screenshot.Question No. 2 answer should also be pasted in the same word file.
Answer:-

Code.1:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
int fd;
char * fifo_one = "/tmp/fifo_one";
mkfifo(fifo_one, 0666);
char buffer[80];

fd = open(fifo_one, O_RDONLY);
read(fd, buffer, sizeof(buffer));

close(fd);

}
Code.2:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
int fd1;
char * fifo_one = "/tmp/fifo_one";
mkfifo(fifo_one, 0666);
char buffer[80];

fd1 = open(fifo_one, O_WRONLY);


write(fd1, buffer, sizeof(buffer));
printf("Noor Ul Huda BC180408636\n");
close(fd1);

Question No. 2 05 Marks


Consider the following three processes, with the Arrival time and CPU burst time, is given in
milliseconds:-

Process Arrival Time Burst Time


P1 0.0 3
P2 1.0 8
P3 3.0 6

A. Draw a Gantt chart showing the execution of three processes using the Shortest
Remaining Time First (SRTF) scheduling.
B. Find the turnaround time of each process for the SRTF Shortest Remaining Time First
scheduling algorithm as per the Gantt chart.
C. Calculate the waiting time for the three processes for the SRTF Shortest Remaining
Time First scheduling algorithm as per the Gantt chart?

Solution;

P1 P1 P1 P3 P3 P3 P3 P3 P3 P4 P4 P4 P4 P4 P4 P4 P4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
P1 P3 P2

0 3 9 17

Process Arrival Burst Time Catch Time Turnaround Waiting


Time Time Time
P1 0.0 3 3 3 0
P2 1.0 8 17 16 8
P3 3.0 6 9 6 0

You might also like