OS ASSIGNMENT fork.
py
Sumanth Guptha & Govind More
January 2024
Introduction
The default fork percentage was set to 0.7
The default settings of showing tree are off and only actions were displayed.
Help Tag -h
The program comes with a -h tag allowing us to view the tags and settings
available. It is shown in image 0.1
1 question 1
The different flags were used.
The -c flag shows the tree at each step.
-a flag allows us to control the number of operations
-s randomises the flags.
The tests were given in images 1.1 and 1.2
2 Question 2
The value of -a was set to 50 and tried with extreme valus of -f
Observation:
The breadth of the tree increases due to susequent child processes when the
value of f is increased.
This shows increases in the fork probability.
The out put images are shown in images 2.1 and 2.2
1
3 Question 3
by setting the -t flag the evolution of the tree is seen at each step but the actions
are left to us for quest.
The output is shown in image 3.1
4 Question 4
The given inputs are tried out.
The out puts are shown in images 3.1 and 3.2.
Observation:
When the -R flag is set then the orphaned branches are getting adopted by the
root.
In the other case the orphaned branched are getting adopted by the grandpar-
ents.
5 Question 5
The -F flag is set and the intermediate actions are given but the final tree and
intermediate steps of tree are left to us to figure out.
The output is shown in image 5.1.
6 Question 6
The -F and -t flags are set together.
the actions and tree were not given but the final tree is given
There different set of actions that can be taken to achieve this single final tree.
The output was shown in image 6.1.
2
CODE SECTION OF ASSIGNMENT
7 Question 1
The variable was assigned before calling the fork.
And edited in both parent and child process.
Initially before editing the values are same.
After Editing the values are different.
This shows that the process and address and variables are independent after
forking.
code is in the submitted assignment.
8 Question 2
Both the parent and child can open the same file at a time.
Writing into it concurrently does effect anything except for the order
This shows only the pointer is accesed and the writing is done by maintaining
buffer.
So the file pointers are different for both the processes.
Both strings written by parent and child are present in the text file.
9 Question 3
sleep() function is used to make this work without wait().
Since the speed of processor is high a wait of 2 seconds ensures that child runs
first. Or Hello is printed first.
10 Question 4
All versions of exec are used in different codes in the submitted file.
There is a significant difference in the syntax and usage of the variants.
Some variants doesn’t allow running a custom program defined by the user and
there are other functions specific to that variant.
11 Question 5
wait return the PID of the child if it exists.
wait returns -1 when there is no child.
But some how using wait in child processing making the parent execute first.
This doubt has not been figured out by our team yet.
3
12 Question 6
WaitPID is more powerful than the wait function.
wait pid allows the parent function to wait for a specific child or pid when there
are multiple child processes.
13 Question 7
When the STDOUT FILENO is closed the output is not redirected to anywhere.
The output of the printf is lost.
And printf does not return a error.
14 Question 8
A single pipe is used to redirect the out put of ls done child process 1 to the
child process 2.
Then wc is applied over the redirected output by the child process 2.
4
Figure 1: image 0.1
15 OUTPUT IMAGES
5
Figure 2: image 1.1
6
Figure 3: image 1.2
7
Figure 4: image 2.1
8
Figure 5: image 2.2
9
Figure 6: image 3.1
10
Figure 7: image 4.1
11
Figure 8: image 4.2
12
Figure 9: image 5.1
13
Figure 10: image 6.1
14