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

Assignment 2 PDF

This document contains instructions and questions for Assignment 02 for the Operating Systems course at National University of Computer and Emerging Sciences Islamabad. It includes 6 questions related to processes in Linux involving creating child processes, inter-process communication, and process hierarchies. Students are instructed to submit individual code files in a zip folder with their roll number as the name. Plagiarism will result in a 500% mark deduction.

Uploaded by

Usama
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)
169 views

Assignment 2 PDF

This document contains instructions and questions for Assignment 02 for the Operating Systems course at National University of Computer and Emerging Sciences Islamabad. It includes 6 questions related to processes in Linux involving creating child processes, inter-process communication, and process hierarchies. Students are instructed to submit individual code files in a zip folder with their roll number as the name. Plagiarism will result in a 500% mark deduction.

Uploaded by

Usama
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/ 4

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING

SCIENCES ISLAMABAD
OPERATING SYSTEMS SPRING 2020

ASSIGNMENT 02

Instructions

• -500% marks will be awarded to the students involved in

plagiarism.

• All the submissions will be done on Google Classroom.

• Create separate file for each question.

• Submit only a single .zip file containing all the codes and keep

your roll number as its name

QUESTION NO. 01
Write a C program, which accepts two command line arguments as inputs.
The Parent process creates one Child and that child will create another child.
Child 2 is only responsible to calculate and return the Sum of both arguments,
while Child 1 will calculate factorial of first argument. The parent process
should wait for the termination of its child process while it also waits to its child
to finish its execution.
Hint: use “atoi” function to convert char array to int

QUESTION NO. 02
Write a C program on Linux platform to implement the below given process
hierarchy. Each process displays its name (e.g. P1), its process ID and the
pro-cess ID of its parent. A process used the getpid () and getppid () system
calls to obtain these IDs. Sample output of the process is:

P1: ID: = 1234, Parent ID = 1123


Operating Systems Spring, 2020 NUCES, Islamabad

Figure 1: Hierarchy of the Processes

QUESTION NO. 03
Write a C program on Linux platform to implement the below given scenario.

You have to solve the following equation: x= (a*b) + (c/d) + (e-f);

Write a code in such a way that each part of equation is solved by child pro-
cesses and parent get results from the child processes and compute the final
result.
For Example,
Child 1 Solves: a*b
Child 2 Solves: c/d
Child 3 Solves: e-f
And Parent will compute x=x= (a*b) + (c/d) + (e-f) after getting the results of
each portion of equation from child processes.
Take values of a,b,c,d,e,f from user in parent process.

Important Note: There should be only one parent process and all the child
be-longs to that parent process.

2
Operating Systems Spring, 2020 NUCES, Islamabad

QUESTION NO. 04
Run the below code again and again, observe the output and explain what is
happening.

Hint: Use "top" command and observe the process table. Also study about
orphan and zombies processes.
Important Note: Submit word file for this question.

QUESTION NO. 05
The default rm command will not confirm before it deletes any regular files.
Write a short script called safe rm, such that it will make a copy before deleting
a single file (that is, we do not use wildcard expressions for this problem) by
do the following:
Take one and only one argument at the command line (hint: search for
an expression representing the number of arguments in the shell
scripts). Print out an error message if no argument or more than one
arguments are provided (hint: use echo).
Create a directory “safe_rm_recycle” in the current one if it is not
already created.
Copy the file indicated by the first argument to this “safe_rm_recycle”
folder.
Remove this file in the current working directory.

3
Operating Systems Spring, 2020 NUCES, Islamabad

QUESTION NO. 06
Write a C program that will help parent and child processes to talk to each
other using Text messages.
Both processes should continue chatting, until one of them asks other "I am
Bored". After receiving "I am Bored" messages, other process will say "Good
Bye" and quit its execution. Process, who sent "I am Bored" message will print
"YEYYY!!!!" to the terminal and quit as well. creates a child process.

THE END

You might also like