Programming Assignment 1C

Version 1.0

Colorado State University

CS370: Operating Systems


DUE DATE:
10:00 pm
Friday February 21st, 2014


Programming Assignment 1C: fork(), wait(), exec()

The purpose of this assignment is introduce the concepts of fork, wait, and exec in the scope of systems programming.


Description of Task

For this assignment you will be creating two programs, recorder and gambler.

gambler

gambler takes a single paramter from the command line r and returns an integer between 1 and 12 (inclusive).

recorder

recorder takes up to 3 parameters and prints output based on the parameters given to it.

The parameters include:

recorder then:


Requirements of Task

  1. recorder must use getopt() to parse up to the 3 parameters described above.

  2. The -r and -v options will always come before the last value (number_of_processes). The -r option and number_of_processes are required, the -v option is optional.

    ex. recorder -r 6 -v 1000
    ex. recorder -r 3 10000

  3. recorder will then spawn number_of_processes children, each of which will exec gambler, making the argument list passed to recorder available to gambler.

  4. recorder can spawn no more than 7 processes at a time so that system performance is not degraded (both in terms of the assignment, and as a kindness to your fellow lab mates).
    • This requirement should be enforced from the beginning of your coding.
    • Test that your code works with small numbers before increasing the number of processes.

  5. recorder will wait() on a child to terminate, record the result, print the childs PID and result if -v is specified, and continue spawning children until it has done the number of processes specified on the command line.

  6. gambler must use getopt() to parse the command line options to get number_of_rolls and generate the integer return code based on r number of rolls passed to it from recorder.

  7. gambler shall use a random number generator routine to generate the correct number of rolls. The random number generated should be seeded from the PID.

  8. gambler returns the highest of those rolls.

  9. You should perform all pertinent error checking (i.e. valid command, valid number_of_rolls, valid number of processes, etc.) Running edge conditions, testing for memory leaks and invalid input will be a part of the grading scripts. If you encounter an error, an appropriate error message should be written to stderr and you should discontinue processing. All error messages should be written to stderr.


Example:

waker> recorder -r 1 -v 4

PID 4567 returned 6.
PID 4568 returned 2.
PID 4569 returned 4.
PID 4570 returned 8.

Created 4 processes.
1 - 0
2 - 1
3 - 0
4 - 1
5 - 0
6 - 1
7 - 0
8 - 1
9 - 0
10 - 0
11 - 0
12 - 0

Example:

waker> recorder -r 1 4

Created 4 processes.
1 - 0
2 - 1
3 - 0
4 - 1
5 - 0
6 - 1
7 - 0
8 - 1
9 - 0
10 - 0
11 - 0
12 - 0


What to Submit

The program files should be well documented with both data dictionaries and logic flow descriptions.

Your makefile should perform a make target, a make clean and a make all. Name the executables per the requirements .

Perform a make target and submit the tar file containing your .c file(s), .h file(s), and Makefile using the RamCT assignment submission page.

You are required to work alone on this lab.

This is Programming Assignment 1C.


Late Policy

Click here for the class policy on submitting late assignments.



Copyright © 2001-2014: Colorado State University for CS370. All rights reserved.