Operating System (CS604) Total marks = 20
Assignment # 01 Deadline Date
Spring 2024 May 2, 2024
Please carefully read the following instructions before attempting the assignment.
RULES FOR MARKING
It should be clear that your assignment would not get any credit if:
The assignment is submitted after the due date.
The submitted assignment does not open, or the file is corrupted.
Strict action will be taken if the submitted solution is copied from any other student or the
internet.
You should consult the recommended books to clarify your concepts, as handouts are insufficient.
Assignment Submission:
You are supposed to submit your assignment in Doc or Docx format.
Any other formats, such as scanned images, PDF, zip, rar, ppt, and BMP, will not be accepted.
You are required to send the Screenshot and C code of Question No. 1 in the same Word file.
Furthermore, Linux commands of Question No. 2 should also be pasted in the same Word file.
Assignment No. 1 covers Labs 1 to Labs 3
OBJECTIVE
The objective of this assignment is to provide hands-on experience in the:
Inter-Process Communication through the pipe System call
Linux File/Directory management commands.
System calls and their usage in Linux
NOTE
No assignment will be accepted after the due date via email in any case (whether it is due to load
shedding or internet malfunctioning, etc.). Hence, refrain from uploading assignments within the
last hour of the deadline. It is recommended that the solution file be uploaded at least two days
before its closing date.
Please consult your instructor before the deadline if you find any mistake or confusion in the
assignment (Question statement). After the deadline, no queries will be entertained in this
regard.
For any query, feel free to email me at:
[email protected]Questions No 01 15 marks
You are required to describe how the following code created in the C program works.
Execute the program in C first, then determine how it works from its output. Also, attach
screenshots of the output.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#define BUFFER_SIZE 256
int main() {
int pipefd[2];
pid_t pid;
char buffer[BUFFER_SIZE];
int nbytes;
// Create pipe
if (pipe(pipefd) == -1) {
perror("pipe");
exit(EXIT_FAILURE);
}
// Fork a child process
pid = fork();
if (pid == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (pid == 0) { // Child process
// Close the write end of the pipe
close(pipefd[1]);
// Read from the pipe
nbytes = read(pipefd[0], buffer, BUFFER_SIZE);
if (nbytes == -1) {
perror("read");
exit(EXIT_FAILURE);
}
printf("Child received message: %s", buffer);
// Close the read end of the pipe
close(pipefd[0]);
exit(EXIT_SUCCESS);
} else { // Parent process
// Close the read end of the pipe
close(pipefd[0]);
// Write to the pipe
printf("Enter message to send to child: ");
fgets(buffer, BUFFER_SIZE, stdin);
write(pipefd[1], buffer, BUFFER_SIZE);
// Close the write end of the pipe
close(pipefd[1]);
// Wait for the child to finish
wait(NULL);
exit(EXIT_SUCCESS);
}
return 0;
}
Questions No 02 5 marks
In the following table, write the details for the given Linux commands.
Linux Command Details
Ls
Cd
Grep
Cat
rm or rmdir
Note: If you have installed the Virtual Box, you can take the Screenshot as follows. Go to the
view menu and click on Take Screenshot as follows.
See the following link for the installation of Virtual Box and Ubuntu (Linux) on your system.
https://vulms.vu.edu.pk/CourseResources/OpenFile.aspx?
File=tutorial_for_installing_virtualbox_and_ubuntu.mp4
See the following link installing gcc and compiling and runnings your first program in Linux.
https://vulms.vu.edu.pk/CourseResources/OpenFile.aspx?File=How%20to%20install%20gcc
%20on%20Ubuntu%20and%20compile%20a%20C%20program.mp4
The End