CS 3733 Operating Systems, Fall 2002 Assignment 3 Comments
The assignment was graded on a basis of 30 points.
Unfortunately, I forgot that I was using the same questions for Part 1 and
Part 2 as last semester and the answers were on the web.
Therefore I did not look at your answers to these questions.
You should compare your answers to the ones given here.
If there is anything you don't understand, see me.
Parts 3 and 4 are new to this semester.
Answers to questions: Part 1
- For which of the 10 experiments was the output in the same
order each time it was run?
Your answers may vary but probably you got 1,2,5,6,9 and 10.
- For which of the 10 experiments is the order of the output
determined by the program?
Some people misinterpreted this question. The output is determined by the
program if the output will be the same, independent of what the operating
system does in scheduling. This is only the case for 9 and 10 in which
the wait determines the order of the output.
- For experiments 1, 8, 9 and 10 explain why you think the output
was in the order that it was?
1: There is no preemption and the parent continued to execute after the fork.
Therefore, the first process finishes first. Since FCFS is used the next
process to execute is the first process created by the fork. The processes
execute in the order of their creation.
8: Because the printing is not atomic, the first process will output only a few
characters before losing the CPU. The only preemption is from this non-atomic
printing so after a process prints some characters all other processes print
something be that process gets a chance to print again.
9 and 10: In both these cases the wait causes each process to wait until
its child has printed to the output is in reverse order of creation.
Answers to questions: Part 2
- Is the tree structure the same in each case? How does it differ?
Some people misinterpreted this question. The tree structure (how many
children the processes have, independent of the labeling) is the same in
each case, but the labels are different.
- The process IDs are assigned in the order of creation. In each case
describe the order of creation relative to the tree structure.
1: The processes are ordered in a breadth-first manner with the processes having
the most children being numbered first.
2:The numbering is a mixture of breadth first and depth first. When a process
is created a chain of children is created in order until the chain is done.
3 and 4: Each of these is almost like the first one, but there are some
modifications as a process loses the CPU early.
- Is the order of the output affected by the scheduling of the processes?
Yes, just as in Part 1.
Part 3:
- You were asked to put the initial write by the first process
in the code after the ring was created. This means it should go after the
for loop and look something like this:
if(i==1) {
   sprintf(buf,"%d",getpid())
   write(1,buf,strlen(buf)+1);
}
- You should understand why the SIGPIPE occurs.
- There are several ways to avoid the SIGPIPE.
- The most straight forward
is to not have the first processes write to the pipe again.
After the fprintf, do:
if(i!=1) {
   sprintf(buf,"%d",getpid())
   write(1,buf,strlen(buf)+1);
}
- Another method is to have process 2 do a second read from the pipe
so that it doesn't exit until process 1 does the second write.
- It is not correct to have all processes do an extra read, as
this will prevent some of them from exiting.
General Comments:
- If it says "preliminary grade" on your paper, it means you need to
fix the problem and hand it in again. Hand in the original and
any additions.
- If a page number is circled on your cover page, look for comments on
that page.
- For Part 2 you were asked to make the tree with the processes with
the most children on the left.
- Be careful when you insert code manually into an HTML document as the
< will be treated as the start of a tag. The simulator handles this
automatically when you log the program.