Operating Systems Project 5


The main goal of this project is to familiarize yourselves with signals.

This is an individual or group project, at your choice. You may collaborate with anybody else and search the web, as long as all the code and results you turn in are authored by you personally. You may use any libraries that are part of any standard distribution of Minix, Linux, or other Posix-like system.

The project is due Friday, October 29th 2004, any time. Submission is by email. Please send me the following:

  1. a brief description of the status (success or lack thereof) of your project. This should include
  2. a copy of your program(s).

Please send in your project on time -- late submissions will not be accepted, and I prefer to have partially-working projects rather than no project at all.

As usual, you are welcome to study any materials on the web.

Description

I want you to write a program that uses alarm(2) to maintain a digital clock. The main part of your process should install a signal handler for SIGALRM, call alarm, then go into an infinite loop. When the signal handler is called it must set the alarm again, then increment a global variable, then check to see (by calling time(2) how much time has actually passed. If the time that has passed doesn't match (by 5 seconds or more) the count of times your handler has been called, your program should print this and exit. Before exiting, your program should print its runtime T, which is the accuracy of your clock -- for example, if it takes 1 hour for the discrepancy to reach 5 seconds, your clock's accuracy is 5 seconds for every hour.

Please run this on a real (not a simulated) machine, so issues of clock accuracy (for the machine) do not arise. If you are running Minix on a simulator, do not run this on your minix, use any other system instead (if you are running your minix on a real machine, you are welcome to run this on your minix).

As well as the accuracy of your clock on an unloaded system, I also want to know the accuracy of your clock on a heavily loaded system, so please report also the accuracy when you are running two copies of your test code at the same time (report both times).

In my own tests, the accuracy has varied quite a bit. If your system is still accurate after an overnight run, you may simply tell me that (you still have to try and account for sources of inaccuracy).

To verify the operation of your system, you should print your system's status (value of the counter and time passed since start) between once about every minute to once every ten minutes (I print every 100 calls to the handler, but if you print every minute it will look more like a digital clock).

If you can't find a better system to run your code on, you can run it on uhunix, but it may be hard to find a specific time when the system is lightly loaded (you can use "uptime" to tell you the load average, anything under 0.5 is lightly loaded). But you are welcome to write this to run under Windows if you like (and if alarm signals and signal handling are supported, which I suspect they are).

I suggest you use sigaction to record the signal handler (as an sa_handler) and to install it permanently (rather than only until the first call). You will still need to call alarm in the signal handler to set the alarm for next time.