Applying the alarm(3) Function

The alarm(3) function is related to signals. It is useful as a simple timer and is used for signal demonstrations in this chapter. The function synopsis is as follows:

#include <unistd.h>

unsigned int alarm(unsigned int seconds);

The alarm(3) function returns the previous alarm setting in seconds and establishes a new timer if the argument seconds is greater than zero. After the call is made and the specified time elapses, the signal SIGALRM is raised. This signal indicates the expiration of the timer. If alarm(3) is called before SIGALRM is raised, the current timer is canceled and a new timer is started. Specifying a value of zero to alarm(3) cancels the timer in progress without starting a new one.

Note

There ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.