CS 3733 Operating Systems, Fall 1998 Assignment 5 Comments
General Comments
Inside programs you should use the symbolic value for signals such as
SIGUSR1 and SIGUSR2 rather than the numbers 16 and 17.
Part 1
More than half of the class got the method for calculating the
sum of an arithmetic progression wrong. If start = 10,
delta = 5, and count = 4,
then numbers to be summed are 10, 15, 20, and 25.
You can either calculate this in a loop or use a formula for the sum.
I took off three points if you did this incorrectly. Many people just
calculated start + delta*count which gives 30 in this case
instead of 70. I took off 3 points if you calculated the sum incorrectly.
Part 2
You should block the SIGUSR2 signal when executing the SIGUSR1
handler and block the SIGUSR1 signal when executing the SIGUSR2
handler. Since these both modify the shared variables giving
the number of signals and the current sum, this is a critical section.
The easiest way to do this is to use one handler for both and block
both signals during its execution. Use the sa_mask
field of struct sigaction for this. I took off 2 points if you
did not block the appropriate signals.
Extra Credit 1
There are several ways of doing this. Here is the simplest way:
Use write in the handler instead of fprintf.
You must be able to convert an integer to an ASCII string without using
the system routines which might not be async-signal safe. Note that a
signal handler can call other functions if they are known to be safe.
It you write something yourself, and it doesn't use any library calls,
you should be able to tell if it is safe to use. Your conversion
function cannot malloc since this might not be safe, but
you can figure out an upper bound for the size of a string which
represents an integer.
Extra Credit 2
To get credit for this the id of the combiner method must be
determined by your program automatically.
One way to do this is with ps.
Have your sum_a program fork a child that execs ps.
Set this up so that the output goes to a pipe which the parent can read.
The parent reads each line of output looking for a process with the right name
and finds the pid from that line when found.