Assignment 2 PDF
Assignment 2 PDF
SCIENCES ISLAMABAD
OPERATING SYSTEMS SPRING 2020
ASSIGNMENT 02
Instructions
plagiarism.
• Submit only a single .zip file containing all the codes and keep
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:
QUESTION NO. 03
Write a C program on Linux platform to implement the below given scenario.
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