OS LAB MidTerm V6 Question Paper
OS LAB MidTerm V6 Question Paper
Question Q1 Q2 Q3 Q4 Q5 Total
Marks 5 10 5 10 10 40
Obtained
1
Question No. 01: Write Linux basic commands to fulfill following operations.
4. Force to remove the directory dir which you have created with a name of
MID.
Question No. 02: What will be the output of the following code and give its
reason.
2
1 int main ()
2 {
3 int pid1 = fork ();
4 int pid2 = fork();
5 int pid3 = fork();
6 if (pid1 < 0 | | pid2 < 0 | | pid3 < 0)
7 {
8 cout << “FORK FAILED… ” << endl;
9 }
10 cout << “Hello, From Process” << getpid() << endl;
11 return 0;
12 }
1. Write the output of the given code, and also explain the reason of the output as well.
2. Draw the process tree for the above code and provide the values of pid1 and pid2.
3. How many at max orphan children will be present in the system mentioned above? How
can we avoid their existence.
Question No. 03: There are exactly 6 syntax errors present in the following
code. Find them and provide the correct syntax in the table below.
[5 marks] CLO 2
3
10 int cpid = wait(pid,NULL,0);
11 cout << "\nMy Child has completed his execution and his id is: "<< cpid << endl;
12 }
13 if(pid == 0){
14 execl(NULL ,"cal");
15 }
16 return 0;
17 }
A. Write a program to demonstrate how a child process become orphaned. Display the
process Id’s of both parent and child.
B. Write a program to create three child processes, where the first child terminates early
(demonstrating a zombie process), the second child runs independently, and the third
child waits for a specific event. Display the process IDs of all processes, and identify
which process becomes a zombie.
4
A: B: