Exercise 2: Alternate Alarms

Problem Statement

Alarms are used to generate signals to the calling process after some specified time. For example, alarms can be used by a sensor reading process, which wakes up periodically, say, every 10 seconds, to record the measured value of the sensor. Alarms are set by processes using alarm (2) system call. Minix in its current form does not allow a process to have more than one alarm timer. When a process calls alarm(), any pending alarm is cancelled.

The objective of this exercise is to create an alternate alarm. This requires you to create a new alarm2() system call with same syntax as the previous alarm() system call. However, the alarm set through the alarm2() system call must generate a different signal, SIGALRM2.

This exercise requires you to understand the implementation of the current alarm () system call and signals.  The definition of the new alarm2 system call is:

 unsigned int alarm2(unsigned int seconds)

Alarm2 must cause a signal SIGALRM2 to be sent to the invoking process in a number of seconds given by the argument. The return value is the amount of time that was previously remaining in the alarm clock. If no previous alarm was set, alarm2 returns 0. Note: Alarm and alarm2 are completely independent. Calling either one does not affect the other one.

Hint: The basic idea is to create a new queue for the alternate alarm. For every clock interrupt, the kernel must scan the alternate alarm queue, in addition to the existing alarm queue.

Evaluation Criteria
 

  • The exercise is a simple one and just requires the comprehension of existing alarm() system call.
  • Modify and use the existing code as much as possible. However, simple cut-and-paste of the existing code must be avoided as much as possible.
  • Solutions will be evaluated on the following criteria:
  • Basic definitions

    The system call number of the alarm2 (ALARM2) system call has to be 79. SIGALRM2 should be defined as 16. Also change _NSIG correspondingly in /usr/include/signal.h. For testing the system call use this stub alarmstub.c.

    Recommended Reading

    Study relevant information about the clock, signals, system calls, and message handling. It is generally important to understand the Minix code on clock interrupt handling (clock.c).

    Questions

    Any questions or queries, mail swami@cs.vu.nl.
    Email first for appointments.