Programming Assignment 1C
Version 1.0
|
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).
- The parameter passed to gambler is an integer between 1 and 10.
- gambler will simulate rolling a 12-sided dice r number
of times.
-
gambler will return the highest number received by r number of
rolls.
recorder
recorder takes up to 3 parameters and prints output
based on the parameters given to it.
The parameters include:
- the same number of rolls r that will be
passed to gambler.
- number_of_processes - and integer between 1 and 100000.
- an optional -v (verbose).
recorder then:
- creates number_of_processes processes
(at no more than 7 active at a time )
-
recorder
should attempt to keep 7 processes running concurrently until completion.
- records the result from each of
the children
- prints out a final count based on the number of possible values on the
dice.
- If verbose mode is selected, it also prints the PID
of each of the children as well as the result.
Requirements of Task
- recorder must use
getopt() to parse up to the 3 parameters described above.
- 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
-
recorder will then spawn number_of_processes children, each of which will exec
gambler,
making the argument list passed to recorder available to gambler.
-
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.
- 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.
- 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.
- 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.
-
gambler returns the highest of those rolls.
- 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 .
-
make target will create the tar file containing the .c file(s),
.h file(s), and Makefile.
-
make all will compile your program(s) according to the specifications
of the assignment.
-
make clean will remove any .o file(s), executables, and tar files in
directory.
- 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.