Question
Write a signal sender and receiver pair of programs.
The sender program (1.5%) must:
- Set up a function that handles SIGINT signals.
This function must:
- Print a message.
- Reset the alarm for 5 seconds later.
- Send a SIGUSR1 to the receiver process.
- Set up a function that handles SIGALRM signals.
The function must:
- Increment the global counter of the number of SIGALRMs
handled.
- Print a message saying how many alarms have been handled.
- Reset the alarm for 5 seconds later.
- Set a global counter of the number of SIGALRMs handled to 0.
- Fork off a child process to run the receiver program.
- Set a SIGALRM for 5 seconds later.
- Run a loop containing a pause() call until 3 SIGALRMs
have been handled.
- Turn off the alarm
- Send a SIGKILL signal to the child process.
- 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:
- Arrange to ignore SIGINT signals.
- Set up a function that handles SIGUSR1 signals.
This function must:
- Print a message.
- 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