CS 3733 Operating Systems, Fall 2000 Assignment 1


Warning: This is not for the current semester.


Due Thursday, September 21, 2000



The purpose of this assignment is to make sure you are familiar with C programming, string manipulation using pointers, use of makefiles, and separate compilation.

Use the cover sheet in /usr/local/courses/cs3733/fall2000/cover1.ps as the first sheet when handing in your assignment. Make sure you include your makefile and lint output.

Put the programs for Part 1 and Part 2 in separate directories and keep all of your source code at least until the course is done.


Part 1. Safe makeargv

Get a copy of argtest.c and makeargv.cfrom /usr/local/courses/cs3733/pup/ch01/run. These are Programs 1.1 and 1.2 from the text. Modify makeargv so that it uses strtok_r instead of strtok. Test it and print out the results of running argtest with appropriate test cases.

Use a makefile to compile argtest and separately and link them together. Your make file should include a line for liniting these together.


Part 2. fork and exec

Write a C program, compileall.c, which takes at least two command line arguments. The first argument is the full path of the c compiler. Each of the additional arguments will be the name of a C source file (without the .c extension).

Find the path of the C compile by executing:
    which cc
This should return something like:
    /opt/SUNWspro/bin/cc

Use this path as the first command line argument when testing your program.

Your program will fork children to compile each of the programs. For an argument "filename", the C compiler will be invoked with:
    /path/cc -o filename filename.c
Each argument will be compiled by a different child.

The parent will wait for the children to complete. When all have completed, it will display a summary of the success of each compilation. For example, if the program were called with:
    compileall /opt/SUNWspro/bin/cc file1 file2 file3 file4
The output might look like this:

   Results of compilation program written by S. Robbins:
      file1: success
      file2: success
      file3: failure
      file4: success
   Number of failures: 1
If there are no failures, the last line should be replaced by:
    All programs compiled correctly

All of this output should appear after the output (including error messages) generated by the compiler.

You may not make any assumptions about the size of any of the strings in this program. Use dynamic allocation where appropriate.

Notes: