0% found this document useful (0 votes)
32 views4 pages

Fall 2023 - CS604 - 1

The document provides instructions for Assignment #01 for the Operating System (CS604) course. It details rules for marking, uploading instructions, and two questions to be answered. Question 1 requires students to create a C program with a parent and child process that create a directory and file, respectively. Question 2 is a table to fill out with correct answers matching details about Linux directories, libraries, process representation, and scheduling. Screenshots of running the code and a VirtualBox Linux environment are requested.

Uploaded by

wajin42077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Fall 2023 - CS604 - 1

The document provides instructions for Assignment #01 for the Operating System (CS604) course. It details rules for marking, uploading instructions, and two questions to be answered. Question 1 requires students to create a C program with a parent and child process that create a directory and file, respectively. Question 2 is a table to fill out with correct answers matching details about Linux directories, libraries, process representation, and scheduling. Screenshots of running the code and a VirtualBox Linux environment are requested.

Uploaded by

wajin42077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Operating System (CS604) Total marks = 20

Assignment # 01 Deadline
th
15 of November
Fall 2023 2023

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.
 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 not sufficient.

UPLOADING INLINE ASSIGNMENT INSTRUCTION


Follow the given instructions to submit Inline assignments:
Microsoft Word (doc/docx) and Adobe Acrobat (pdf) file uploading options will not be available in inline
assignment submission.
 Students can submit HTML, Images, and plain text only in this inline Mode. You may also insert an image
file/table.
 Students can insert the images or snapshots in the following formats.

 Images and tables can be inserted using the following highlighted option in the interface .

OBJECTIVE
 The objective of this assignment is to provide hands-on experience in the:
 Process creation in Linux
 Linux file and Directory creation through C Program.
 Process information and Linux Directory Structure
NOTE

No assignment will be accepted after the due date via email in any case (whether it is the case of load shedding
or internet malfunctioning etc.). Hence refrain from uploading assignments in the last hour of the deadline. It is
recommended to upload the solution at least two days before its closing date.

If you people find any mistake or confusion in the assignment (Question statement), please consult with your
instructor before the deadline. 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 create the C program, that creates the parent and child process the functionality of the
parent and child process is as follows.
 The parent process creates the directory with your name in your current working directory using the
mkdir() system call with access permission as 0777.
 In the child code, it creates the file with your name in the current working directory by using the
fopen() library function.

The following should be the flow of your program.


 Firstly, compile your C program through the command line.
 Run your program.

Solution:

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

int main() {
pid_t pid;
int status;
const char *dirname = "Syed Kumail Abbas Naqvi"; // Replace with your actual name
const char *filename = " SyedKumailAbbasNaqvi.txt"; // Replace with your actual name, adding .txt
extension

// Creating a new process


pid = fork();

if (pid == -1) {
// Error handling if fork() fails
perror("fork failed");
return -1;
} else if (pid > 0) {
// Parent process
// Create a directory with 0777 permissions
if (mkdir(dirname, 0777) == -1) {
perror("Cannot create directory");
return -1;
} else {
printf("Directory \"%s\" created by parent process\n", dirname);
}
// Wait for child process to finish
wait(&status);
} else {
// Child process
// Create a file in the current working directory
FILE *file = fopen(filename, "w");
if (file == NULL) {
perror("Cannot create file");
return -1;
} else {
fprintf(file, "This file is created by child process\n");
printf("File \"%s\" created by child process\n", filename);
fclose(file);
}
}
return 0;
}
Note: You are required to send the screenshot along with the C Code.
Following is the sample screenshot:

Questions No 02 5 marks

In the following table write the correct answer for the given details.
Detail. Answer
The directory name____contains the devices /dev
available to Linux.
To access the home directory ___symbol is ~ or $HOME (environment variable)
used.
By using the gcc command, you can link a -l or -llibrary_name
library explicitly by using the ____option.
Each process is represented in the operating Process Control Block (PCB) or Task Control
system by using a _____data structure. Block (TCB)
medium-term scheduler, which removes Swapping or swapping out to secondary
processes from memory and stored in a storage
place is called the:

Note: in case 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 running 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

You might also like