CS 3733 Operating Systems, Spring 2003 Assignment 1


Due Thursday, February 6, 2003

Assignment 1 has 4 parts.


Part 0:
Make a directory called assign1 with subdirectories part0, part1, part2 and part3. Put all of the code for each part of the assignment in one of these directories.

If you have not already done so, get your readline function from assignment 0 working correctly. Put it in a file called readline.c in the part0 directory along with the programs you write to test the readline.

Part 1:
Put the contents of this tar file in your part1 directory. It contains a makefile that you can use to compile and lint the programs from the rest of the assignment. It also contains a version of makeargv, a program called sleeper and some input files that you can use to test this assignment.

Write a program called readex that has no command line arguments. It reads one line from standard input (using your readline), uses makeargv to convert the input line into an argument array, and forks a child that calls execvp with this argument array. The parent process waits for the child to complete and prints the exit status of the child process. (See PUP Sections 2.5 - 2.7.) Your program should do complete error checking. If an error occurs, print an informative message and exit. Use a buffer size of 1024 for the readline. Do this by inserting the following line in your readex program:
#define BUFSIZE 1024
Do not directly refer to the value 1024 anywhere in your program.

The sleeper program will be used to test the later parts of this assignment, but it can also be used to test Part 1. This program takes at least 2 command line arguments. The first is a sleep time and the second is an exit status. The program starts by checking that it has at least two command line arguments. It prints its process ID and the time the program was started, followed by its argv array. It then sleeps for the sleep time and prints a similar message again. The program then exits with an exit status corresponding to the second command line argument.

Run
sleeper 2 3 abc def gh
from readex and save the output to be turned in.

Part 2:
Copy all of the files from Part 1 into your part2 directory. Modify readex so that it reads lines from standard input until an end of file occurs. An end of file is indicated by a 0 return value from readline. After each line has been processed, wait only for those children that have already completed. (See Example 2.11 from PUP on page 51.) Keep track of the number of children that completed successfully (exit status 0) and the number that completed unsuccessfully. When an end of file occurs, wait for all children to complete. Each time a child is waited for (either before or after the end of file) print the exit status of that child. Before the program terminates, print a line giving the total number of children that completed successfully and the total that completed unsuccessfully.

Test the program with:
readex < infile1
and save the output generated. Turn this in with your assignment.

Part 3
Copy all of the files from Part 2 into your part3 directory. Modify readex so that it takes a single command line argument, n, the maximum number of children to be executing concurrently. Modify readex so that if n children have not been waited for, the process blocks waiting for a child before reading the next input line. Before reading any input line is should still wait (without blocking) for any children that have completed and output the corresponding exit status. Be sure that you:

Test the program with the following:
readex 4 < infile1
readex 2 < infile1
readex 3 < infile2
and save the output generated by each. Turn this in with your assignment.


Turning in the assignment.
Use the cover sheet and include all source files, lint output, and test output asked for on the cover sheet. For each program that you write you should run lint and save the output generated. You should understand all lint warning, and correct your code to remove warnings that should not be there. You should not have any implicitly declared to return int messages. Turn in the hard copy on the due date.

Many of the assignments will have a cover sheet like the one for this assignment. Number the pages you turn in consecutively, starting with page one after the cover sheet. Fill in the appropriate blanks on the cover sheet with page numbers. This acts as a table of contents. For each program there is usually a box to check if you think the program is working correctly, and a similar box later to check if you think the entire assignment is correctly done. If you do not check this box, you must describe on the cover sheet what parts of the assignment are working correctly and what progress you made on the parts that are not working correctly.