Fall 2023 - CS604 - 1
Fall 2023 - CS604 - 1
Assignment # 01 Deadline
th
15 of November
Fall 2023 2023
Please carefully read the following instructions before attempting the assignment.
You should consult the recommended books to clarify your concepts as handouts are not sufficient.
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.
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.
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
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