CS 3733 Operating Systems Assignment 1



Overview
This assignment is related to process scheduling, but you do not have to know anything about process scheduling to do this assignment. The connection of this assignment to process scheduling will become clear in Assignment 2.

You will be given an input sequence of exactly 7 integers. From this you will produce two output strings consisting of the letters R, w and r. You will also produce two integer values giving the number of times r occurs in the first string and the number of times r occurs in the second string. Lastly you will produce two floating point numbers. The first of these is the average of the two output integers and the second is the total number of R's in the two strings divided by the length of the longer string.

You will write a single C program that takes the 7 input values as command line parameters. The program should start by checking that there are exactly 7 parameters and exit with an appropriate error message otherwise. If the number of command line parameters is correct, the program will print your name on a line in the form:
Assignment 1 program was written by ...
and then output 7 input values.
It will then display 5 additional lines: a blank line, a heading, the two output strings (the second directly under the first) and the four numeric values.

Produce a single makefile for compiling all of the programs in this assignment. A sample makefile can be found here.

In writing your programs, follow the programming style guidelines here.

Make sure you understand the statement of the each part before writing any code for that part. For each part you will be given information about how to produce the output from the input sequence.

You will run the program with appropriate input of your choosing to test to see if it is working. Save the output generated to be handed in with your assignment.

You will produce two source files, assign1.c and pslibrary.c. The first will contain your main program. The second will contain functions implementing most of the assignment. In each part you will add to the source files keeping the previous capabilities.

Part 0:
This is just to get you started. You do not have to hand in anything for this part for Assignment 1. The submission deadline can be seen in the following.

Create a directory called assign1 for this assignment. Write a main program called assign1-0.c. This program takes exactly 7 integer command line parameters. It should check for the correct number of command line parameters, assume that all are integers, print a line containing your name and a line containing the values of the parameters. The output should be in the form:
Assignment 1 program was written by Tongping Liu
inputs: 0 2 4 6 7 8 9
If the number of parameters is incorrect, print an appropriate message and exit.

The main program should then create two arrays of characters that will be large enough to hold the character string you will be creating. The maximum size of any of the strings will be the sum of the last six command line parameters. If an error occurs in creating these arrays, exit the program with an appropriate error message. Otherwise call two functions, one to create the strings and one to print them out as follows:
void part0(char *s1, char *s2);
void display(char *heading, char *s1, char *s2);


These two functions should be put in the file pslibrary.c. Put prototypes for these in pslibrary.h and have assign1-0.c include pslibrary.h.

For this part of the assignment use the heading: "Part 0\n". The part0 function will just copy the following strings into the two parameters: RRwwwwwRRRRRRRRR and rrRRRRwwwwwwwwrrRRRRRRR and return. Note that part0 ignores all of the input parameters (s1 and s2 here). Call the program with parameters that are large enough so that the main program will allocate enough space for these strings.

The display function that you write for this part will be used in the next part of this assignment and in future assignments.The display function prints only to standard out and does the following: Run Part 0 and save the output generated.

Note: When you run Part 0, make sure that the command line parameters are large enough so that there is enough room for the strings.

Part 1:
Write a function in pslibrary.c called fcfsa that takes two string parameters and 6 integer parameters. It fills in the strings for the first two parameters as described as follows. Suppose the function is called with
fcfsa(s1, s2, x1, y1, z1, x2, y2, z2);
The first string, s1, will consist of a x1 R's, followed by y1 w's, followed by 0 or more r's, followed by z1 R's.
The number of r's will be described later.

The second string, s2, will be consist of x1 r's, followed by x2 R's, followed by y2 w's, followed by 0 or more r's, followed by z2 R's.

The number of r's in each string will determined by the following conditions:
  1. The two strings strings will not have R's in the same position.
  2. No string will have an r in the position that the other string has an r or w.
  3. The first string will have the smallest number of r's that will allow it to satisfy conditions a) and b).
  4. The second string will have the smallest number of r's that will not contradict a), b), or c).
Copy assign1-0.c into assign1.c and have assign1.c call fcfsa using the last 6 integer parameters (ignore the first integer parameter) instead of calling part0 It will then call display.

Example 1:
With the input sequence: 0 4 2 7 3 6 5
the output generated by display should be:
RRRRwwrRRRRRRR
rrrrRRRwwwwwwrRRRRR
1 5 3.0 1.00000

Example 2:
With the input sequence: 0 4 9 5 6 3 7
the output generated by display should be:
RRRRwwwwwwwwwRRRRR
rrrrRRRRRRwwwrrrrrRRRRRRR
0 9 4.5 0.88000

Test your program with inputs you have developed. Then run the program with each of the following six tests. For each, save the output in a file and print the output, each on a single page. Label each one as Test 1, Test 2, Test 3, Test 4, Test 5, or Test 6.

Test 1: 3 8 7 3 6 3 2.
Test 2: 3 8 7 3 6 7 2.
Test 3: 4 8 7 3 6 1 2.
Test 4: 3 3 3 4 2 1 2.
Test 5: 3 3 2 3 2 1 2.
Test 6: 3 5 2 5 4 1 1.
This will be turned in with your assignment. Put the page number of each of these on the cover sheet under Final test output 1, etc.

A Final Test:
Get a copy of this program.
Compile this program with you pslibrary as follows:
cc -o runalla runalla.c pslibrary.c.
Then execute runalla. It should create a file called fcfsa.all.
Execute:
ls -l fcfsa.all
wc fcfsa.all
md5sum fcfsa.all
and include the output with your assignment.
The fcfsa file should have 2,000,001 lines and 2,000,003 words.
You should delete this large file after you have saved the above output.


Submission guideline

You will submit through the blackboard. Please including the "status.txt", and a "source" directory that includes all source code and Makefile.
"source" directory: mandatory
This directory should include all of your source code (*.c, *.h) and Makefile. Without the soure code, you can only get 50% points of your earned at most.
status.txt: manadatory
You should include a status report in the file status.txt. Here, the status report in status.txt should include whether you have completed each part of not. If successful, please add the output of your display for each test. Also, please include last 4 hexadecimal digits of the md5sum. Otherwise, please also give brief description of what is working and what progress was made on the part that is not working. There will be a severe penalty (50% off) if the "status.txt" is not aligned with your source code. If there is no "status.txt", you won't get any points.

Please compress all of these files into a zipped file and name it as "abc123.zip". abc123 should be replaced with your abcid.




Based on materials provided by Prof. Steve Robbins.