0% found this document useful (0 votes)
34 views

Assignemnt OS

This document contains instructions for an assignment on operating systems principles. It includes 3 questions to answer in handwriting: 1) Explain why there is only one arrow entering the "Running" process state but multiple arrows leaving it. 2) Describe the role of the init process on terminating processes in UNIX and Linux systems. 3) (a) Determine the number of processes created by a sample C program. (b) Explain when a specific print statement would execute. (c) Identify the pid values at labeled points in another C program.

Uploaded by

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

Assignemnt OS

This document contains instructions for an assignment on operating systems principles. It includes 3 questions to answer in handwriting: 1) Explain why there is only one arrow entering the "Running" process state but multiple arrows leaving it. 2) Describe the role of the init process on terminating processes in UNIX and Linux systems. 3) (a) Determine the number of processes created by a sample C program. (b) Explain when a specific print statement would execute. (c) Identify the pid values at labeled points in another C program.

Uploaded by

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

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;
}

You might also like