O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The good ol' alarm clock

The alarm(2) system call allows a process to set up a simple timeout mechanism; its signature is as follows:

#include <unistd.h>unsigned int alarm(unsigned int seconds);

It is, indeed, quite self-explanatory. Let's take a simple example: A process wants to set up a timer that will expire in three seconds from now, so alarm(3) is essentially the code to use to do this.

What exactly happens in the aforementioned code? Three seconds after the alarm system call is issued—that is, after the timer has been armed—the kernel will send the signal SIGALRM to the process.

The default action of SIGALRM (signal # 14 on x86) is to terminate the process.

Thus, we expect the developer to catch the signal (via the sigaction(2) system ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required