CS 3733 Operating Systems, Spring 2006 Assignment 1


Originally due Friday, February 10, 2006

Revised due date: Monday, February 13, 2006.


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 this cover sheet as the first sheet when handing in your assignment. Make sure you include your makefile and lint output.

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


Part 0: mystrtok

Write a function called mystrtok that has a similar prototype and behavior as strtok_r. Write this from scratch. Do not use any library routines.


Part 1: Safe makeargv

Get copies of argtest.c and makeargv.c from the USP web site. Modify makeargv so that it uses mystrtok 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 linting 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
On the Solaris machines this should return something like:
    /ropt/SUNWspro/bin/cc
On the Linux machines this should return something like:
    /usr/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 /ropt/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:

Additional Notes: