CS 3733 Operating Systems, Fall 1998 Assignment 3 Comments
General Comments
If I have written a small circled number to refer to something
on your assignment, it refers to the following:
- A lint warning that a system function is implicitly declared to return int
means that the appropriate header file was not included.
- A lint warning that one of your functions is implicitly declared to return
int means that you did not include a prototype of that function
- Do not hard code in the size of an int as 4.
- drand48 is a poor random number generator in that when the seeds are close
the values generated will be related.
- When linting the rings, lint with myrandom.c also.
Part 1
How close is close? What do you expect the range of counts to
be? One way to tell is to look at the standard deviation.
Theoretically, the standard deviation should be sqrt(99/12)
which is about 2.87.
Part 2
Running for the same number of processes on the same machine
will usually produce the same order, but there is nothing that
guarantees a particular order or that the order will always be
the same.
The prompt appears when the original process terminates.
If a process's parent terminates before the process gets its
parent id, the parent id will be displayed as 1, the init process
which inherits all processes whose parent no longer exists.
Part 3
All processes should generate the same random number since the
initialization is done before the fork and so each process has a
copy of the same initialization. The initialization should be
before the start of the loop or it will be called several times,
including after the first fork.
Part 4
Now the processes generate independent random numbers.
You should get different results each time it is run.
The order of the messages should reflect the order of the
random numbers generated.
Part 5
Each process should print out the value corresponding to the pid
of its original parent (usually one less than its pid) except
for the first process which should print the pid of the last process.
Because the print is after the write, it is possible for a process
to print before its predecessor. Note that you are supposed to
read and write integers as 4-byte quantities. Do not use fprintf
and fscanf to send information around the ring. These send
character strings.
Part 6
Since all processes are blocked on the read, no process will do
any I/O after the fork.
Part 7
Now the processes will usually print out in order with the first
process coming last. It is possible for the output to be different
if a process loses the CPU between the read and the fprintf.
Often, the first process will terminate when it
does its second write to the ring if process 2 has already exited
due to the SIGPIPE signal it receives.