COMSATS University Islamabad (Lahore Campus)
Assignment <1>– Spring 2024
Course Title: Principles of Operating Systems Course Code: CSC323 Credit Hours: 4(3,1)
Course Instructor: Nadeem Ghafoor Chaudhry Programme Name: BCS
Due Date: Wednesday, March 6th 2024 Maximum Marks: 35
Important Instructions / Guidelines:
Answer all questions in your own handwriting.
Question No 1. Marks: 10
CLO: <2>; Bloom Taxonomy Level: < Analyzing >
In the Process State diagram there is only one arrow going into the Running
state, but several going out of it, why?
Question No 2. Marks: 10
CLO: <2>; Bloom Taxonomy Level: < Analyzing >
Explain the role of the init (or systemd) process on UNIX and Linux
systems in regard to process termination.
Question No 3. Marks: (2+5+8=15)
CLO: <2>; Bloom Taxonomy Level: < Analyzing >
a) Including the initial parent process, how many processes are created by
the following program if no error occurs?
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid t pid;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else
if (pid == 0) { /* child process */
execlp("/bin/ls","ls",NULL);
printf("LINE J");
}
else { /* parent process */
wait(NULL);
printf("Child Complete");
}
return 0;
}
b) Explain the circumstances under which the line of code marked
printf("LINE J") in the above code will be reached.
c) Using the program given below, identify the values of pid at lines A, B,
C, and D. (Assume that the actual pids of the parent and child are 2600
and 2603, respectively.)
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid t pid, pid1;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else
if (pid == 0) { /* child process */
pid1 = getpid();
printf("child: pid = %d",pid); /* A */
printf("child: pid1 = %d",pid1); /* B */
}
else { /* parent process */
pid1 = getpid();
printf("parent: pid = %d",pid); /* C */
printf("parent: pid1 = %d",pid1); /* D */
wait(NULL);
}
return 0;
}