CS 3733 Operating Systems, Fall 1998 Assignment 3
Was due Thursday, October 22, extended until Tuesday, October 29
In this assignment you will explore concurrency and communication between
related processes.
Create a directory for this assignment and put all programs in that directory.
You should have a makefile for doing all compiles and you should always
run lint. You will hand in a report with the results from all of the
parts as described below. Use the cover page available in
/usr/local/courses/cs3733/fall98/assign3.
There are 8 parts to this assignment, but each part is very short.
Parts 1 and 2 are independent of each other. Each of the other parts
requires all of the previous parts to have been completed.
Part 1
Find out how to generate random numbers on our system using
drand48. You can do this from the man pages
or from the brief description in PUP, page 498.
Create a file called myrandom.c. This should contain two
functions with external linkage.
void initialize_random(long seed);
will initialized the random number generator using the given seed and
int get_random_integer(int low, int high);
will return a uniformly distributed pseudorandom integers between
low and high, inclusive.
Write a main program called test_random.c which will be in a separate
file from your get_random_integer function. It will use its
process ID as a seed and will call this
function 10,000 times using low = 1 and high = 10. It will
keep a count of the number of occurrences of each value between 1 and 10 as
well as the number of values returned which were less than 1 and the number
which were greater than 10, and print out the results. The first line of output
from your test program should be in the form:
This program was written by ...
Print out the source code, lint output, and the output from two runs of
your test program.
Discuss the results indicating why they show the program is or is not working.
Part 2
Obtain a copy of Program 4.1 from PUP from
/usr/local/courses/cs3733/fall98/assign3.
Modify the program by having it start by printing out your name.
Call the modified program ringa.c
Run ringa with a command line argument of 6 several times.
Use cut and paste to get the output of one of these runs and include
it in your report. Do not run the program by redirecting the output
to a file. Describe the results of the runs. Did the messages get
printed out in the same order each time? Why do you think the order came out
as it did?
Part 3
Copy ringa.c into ringb.c and modify it so that the random
number generator is initialized exactly once before the ring is set up
using the process id of the process as a seed.
Have each process clacluate a random number of seconds
between 1 and 10 and sleep for that time before the final fprintf.
Modify the message
so that it also contains the amount of time slept. Again use cut and paste
to include a copy of the output with your report. Explain why the output
appeared as it did.
Part 4
Copy ringb.c into ringc.c and move the initialization
of the random number generator to be near the end of the program, right before
the process gets the random sleep time.
Use the process id of the calling process as the seed.
Again use cut and paste
to include a copy of the output with your report and explain
how and why this differs from Part 3.
Explain why the order came out the way it did.
Part 5
Copy ringc.c into ringd.c. Modify ringd.c so
that after the sleep, the process
writes its process ID (as a raw 4-byte integer) to standard output and
reads a raw 4-byte integer from standard input.
Modify the output message so that in includes the value read.
Use read and write system calls here rather than
fprintf and fscanf.
The write should be before the fprintf to standard
error and the read should be after it.
Again use cut and paste
to include a copy of the output with your report and explain
how this differs from Part 4.
Part 6
Copy ringd.c into ringe.c. Interchange the
two I/O statements added in Part 5. Describe the results of running the
program and explain why it behaved as it did.
Part 7
Copy ringe.c into ringf.c. After the ring has been created,
but before any other I/O or sleeping,
have only the first process (the original parent) write its process ID to
standard output. Again run the program with 6 processes, use cut and paste
to include a copy of the output with your report and explain
how and why this differs from Parts 5 and 6. Look at this one carefully
to see if there is anything that is missing that should be there.
Part 8
Organize your output into a single report. Number of pages consecutively,
and use the cover sheet as the first page. Fill in the index on the cover
sheet. Be sure to include the lint output from all of the programs
and be sure that all warning messages can be ignored.