CS 3733 Operating Systems, Fall 2000 Assignment 3



Warning: This is not for the current semester.


Due Thursday, October 26, 2000


In this assignment you will use the ring of processes, Program 4.1, to do a simple calculation. Read Section 4.2 of PUP to get a background for the problem. The problem you will do is similar to the one described there.

Make a directory called assign3 for all of the files for this assignment. Copy Program 4.1 from /usr/local/courses/cs3733/pup/ch04/ring.c to your assign3 directory. Compile it and make sure it works correctly. Make any changes necessary to eliminate and lint warnings which should not be there. Experiment with the program using a small number of processes and determine whether the order of the output is predictable.

Now rename the program fib.c and modify it so that it starts by displaying your name. The first is the number of processes in the ring to create (as before) and the second is how many Fibonacci numbers to calculate.

Unlike the problem described in the text, information will flow around the ring as many times as necessary (maybe less than once) until the desired number is calculated.

The original parent will start by sending the string "2 1 1" to the next process. Each process will use the information it gets to calculate the next Fibonacci number. At each stage, a process will send a string representing three integers, the number of the last Fibonacci number calculated, and the last two Fibonacci numbers calculated. For example, the process receiving "2 1 1" will send "3 1 2" and the next one will send "4 2 3" and so on. This continues until the requested number has been calculated. At this point the process displays a message to standard error giving the value of i, its process ID, the index the of Fibonacci number it found and the number itself.

At this point the processes send an empty string around the ring, each process exiting after it passes the string to its neighbor.

Each process will display a message to standard error after it calculates the next Fibonacci number and before it sends the information to its neighbor. The form of the message will be:
Process i with PID x and parent PID y received n a b and sent m b c.
The value of m will be n+1.

Each process will also display a message to standard error before it terminates. The message should contain the value of i and the process ID.

Try to implement this is such a way as to maximize the limit on the largest Fibonacci number that can be correctly calculated.

The cover sheet can be found at /usr/local/courses/cs3733/fall2000/cover3.ps and indicates what should be handed in.

The program puts a heavy load on the system.
Do not run this on pandora or any other of our servers.

Sample output:

fib 4 10
This program was written by S. Robbins
This is the first process with id 13494
Process 1 with PID 13494 and parent PID 25210 sent 2 1 1.
Process 2 with PID 13495 and parent PID 13494 received 2 1 1 and sent 3 1 2.
Process 4 with PID 13497 and parent PID 13496 received 4 2 3 and sent 5 3 5.
Process 3 with PID 13496 and parent PID 13495 received 3 1 2 and sent 4 2 3.
Process 1 with PID 13494 and parent PID 25210 received 5 3 5 and sent 6 5 8.
Process 2 with PID 13495 and parent PID 13494 received 6 5 8 and sent 7 8 13.
Process 4 with PID 13497 and parent PID 13496 received 8 13 21 and sent 9 21 34.
Process 3 with PID 13496 and parent PID 13495 received 7 8 13 and sent 8 13 21.
Process 1 with PID 13494 and parent PID 25210 received 9 21 34 and sent 10 34 55.
Process 2 with PID 13495 found Fibonacci number 10 to be 55
Process 2 with PID 13495 is exiting normally
Process 4 with PID 13497 is exiting normally
Process 3 with PID 13496 is exiting normally

Notice that in the sample output above, one of the processes did not produce an exiting message. You may experience something similar. We will learn about why this occurs when we discuss signals.