CS 3733 Operating Systems, Fall 2000 Assignment 4



Warning: This is not for the current semester.


Due Thursday, November 16, 2000


In Assignment 1 you wrote a program which would have children compile parts of a program. We extend this here to do the same thing with unrelated processes. This assignment has 6 parts, but each part is a small modification of the previous one or code already written for Assignment 1.

Use a single makefile to compile and lint the various parts of this assignment. Keep all of your code. You will need it for Assignment 5.

For each part you should collect test output using cut and paste and prepare a file which contains the output showing that your program works. In some cases you will have to take output from more than one window.

Part 1
Make a directory called assign4 for all of the files for this assignment. Write a main program called compileone which takes two command line arguments. The first is the path of the c compiler (as in Assignment 1) and the second is the name of a FIFO (named pipe). The program reads one token from the named pipe and forks a child to compile the corresponding program. The token is the name of the file without the .c. You may assume a reasonable maximum size for the token. It waits for the child and reports either success or failure. This is similar to what was done in Assignment 1.

You can test this program by opening another window in the same directory and using cat to send the name of a file to the named pipe. You should create the named pipe once (using mkfifo from the command line).

Part 2
Copy compileone.c into compiledaemon1.c. Modify it so that after it waits for the compile, it tries to read another token from the named pipe. Since it is possible that there may be more than one token in the pipe when you attempt to read, read one character at a time until you reach a delimiter. The valid delimiters are blank, tab, and newline. You may assume that each token is followed by at least one delimiter. Since there may be more than one delimiter between tokens, you will also have to skip leading delimiters. Now modify it so that it creates an object file rather than an executable, using
cc -c filename.c
Test this again as in Part 1. Make sure you test it with more than one token in the pipe.

Part 3
Copy compiledaemon1.c into compiledaemon2.c. Modify compiledaemon2 so that it reads three tokens for each compile, the first two tokens being integers. For now, just print out the integers found.

Part 4
Copy compiledaemon2.c into compiledaemon.c. Modify it so that it sends either a SIGUSR1 or SIGUSR2 realtime signal to the process whose PID was the first token depending on whether there was a success (SIGUSR1) or a failure (SIGUSR2). The value sent with the signal is the second token. You may have to compile the program using the realtime library, using -lrt on the compile line.

Get a copy of Program 5.4 from /usr/local/courses/cs3733/pup/ch05/prog05.04.c and rename it signalwait.c. Modify it so that it can handle both SIGUSR1 and SIGUSR2 signals. You can do this by just duplicating the sigaction lines. The signal handler does not have to be modified.

Test compiledaemon as before by sending three tokens to the named pipe using cat while the signalwait program is running. The first token should be the PID of the signalwait program.

Part 5
Write a main program called makeit5 which takes command line parameters like the program from Assignment 1. Instead of forking children to do the compiles, it has compiledaemon programs do it. This version will use three named pipes: pipe1, pipe2, and pipe3. It will divide up the files to compile as evenly as possible and send the names of the programs to compile to these pipes. For each file it will send three tokens: its PID, a small integer representing which file it is sending (the first being 0, the second being 1, etc.) and the name of the program.

Your program will then wait for signals to come in and report the results as in Assignment 1.

Note that your program will not be using the first command line parameter unless you do the extra credit part.

Part 6
Copy makeit5.c into makeit.c Modify it so that it reads the names of the pipes from a file called pipes. You can assume that the names are each on a separate line and that there are at most 10 pipes in the file.

Extra credit If your program from Part 5 receives signals indicating that all compiles were done correctly, it should exec the C compiler to link the parts together to produce an executable.

Handing in your program.
Use a single makefile to make and lint the parts of this assignment. Get the cover sheet from /usr/local/courses/cs3733/fall2000/cover4.ps. It indicates what is to be handed in. Provide output from each part indicating how you tested your program to convince yourself that it is working correctly.