Question

Write a signal sender and receiver pair of programs.

The sender program (1.5%) must:

  1. Set up a function that handles SIGINT signals. This function must:
    1. Print a message.
    2. Reset the alarm for 5 seconds later.
    3. Send a SIGUSR1 to the receiver process.
  2. Set up a function that handles SIGALRM signals. The function must:
    1. Increment the global counter of the number of SIGALRMs handled.
    2. Print a message saying how many alarms have been handled.
    3. Reset the alarm for 5 seconds later.
  3. Set a global counter of the number of SIGALRMs handled to 0.
  4. Fork off a child process to run the receiver program.
  5. Set a SIGALRM for 5 seconds later.
  6. Run a loop containing a pause() call until 3 SIGALRMs have been handled.
  7. Turn off the alarm
  8. Send a SIGKILL signal to the child process.
  9. Clean up the zombie of the child process.
Each time the alarm goes off the sender gets closer to termination (of the while loop). A SIGINT (generated by ^C on the keyboard) saves the program from an impending alarm.

The receiver program (0.5%) must:

  1. Arrange to ignore SIGINT signals.
  2. Set up a function that handles SIGUSR1 signals. This function must:
    1. Print a message.
  3. Run an infinite loop containing a pause() call.
A sample run look like this:
SignalSender just got alarm 1
^CSignalSender just got an interrupt
SignalReceiver just got an SIGUSR1
^CSignalSender just got an interrupt
SignalReceiver just got an SIGUSR1
SignalSender just got alarm 2
^CSignalSender just got an interrupt
SignalReceiver just got an SIGUSR1
SignalSender just got alarm 3

Answer