CS 3733 Operating Systems, Fall 1998 Assignment 5

Due Thursday, November 12 at the start of class


You are going write two programs which will illustrate how signals can be used to allow processes to cooperate in a claculation. The first two parts can be tested independently. Last last part tests the first two parts together.

Use the cover sheet in /usr/local/courses/cs3733/fall98/assign5/cover5.ps.

Programs from Chapter 5 of PUP are available in /usr/local/courses/cs3733/pup/ch05.

Note that under Solaris, when you compile programs which contain POSIX.1b functions such as sigqueue, you need to compile using the posix4 library by putting -lposix4 at the end of your cc command.

Part 1:

Write a program called sum_a which computes the sum of an arithmetic progression and sends the result to another process with a realtime signal.

The program will take 4 integer command line parameters: a process id, a start value, a delta value, and a count. The process adds count numbers which form an arithmetic progression. The progression starts with start and has difference delta. When completed, the sum is sent to process id as part of the info structure of a POSIX.1b realtime SIGUSR1 signal.

Test this program with Program 5.4 from the text to receive the signal.

Part 2:

Write a program called combiner which computes the sum of values passed to it through signals. It is started with no command line parameters and starts by printing its process id to standard output. It initializes an integer variable, sum, to 0 and waits for signals to come in. When a realtime SIGUSR1 signal arrives, it adds the data value to sum and prints out the number of values received so far, the current value received, and the sum.

When a SIGUSR2 signal arrives, it clears the count and sum and prints out a message indicating it has been reinitialized.

Test this program using Program 5.3 from the text to generate the signals.

Part 3:

Test Parts 1 and 2 together. Use at least 3 processes from Part 1 with one from Part 2.

Extra Credit 1:

On some systems, the C library is not async-signal-safe. In particular, functions in the printf family, including sprintf and fprintf, cannot be safely used in signal handler. Rewrite Part 2 so that only POSIX.1 async-signal safe functions are called from the signal handler. See Table 5.3 on page 191 of PUP for a list.

There are several ways of doing this. The method you use must be robust. It should work correctly no matter what the timing of the receiving signals is.

Write a short report describing the methods you used and why you think your solution is robust.

Extra Credit 2:

Rewrite Part 1 so that it is not passed the process id of the combiner program. You may assume that one and only one copy of a program called combiner is running on the machine. Implement and test his. Write a short report describing your method.