[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    alarm(2) manual page Table of Contents

Name

alarm - set a process alarm clock

Synopsis

#include <unistd.h>

unsigned alarm(unsigned sec);

MT-Level

Async-Signal-Safe

Description

alarm() instructs the alarm clock of the calling process to send the signal SIGALRM to the calling process after the number of real time seconds specified by sec have elapsed (see signal(3C) ).

Alarm requests are not stacked; successive calls reset the alarm clock of the calling process.

If sec is 0, any previously made alarm request is canceled.

fork(2) sets the alarm clock of a new process to 0. A process created by the exec family of routines inherits the time left on the old process’s alarm clock.

Calling alarm() in a multi-threaded process linked with -lthread (Solaris threads) and not with -lpthread (POSIX threads) currently behaves in the following fashion:

The above documents current behavior and the bugs are not going to be fixed since the above semantics are going to be discontinued in the next release.

The semantic for Solaris threads will move to the per-process semantic specified by POSIX at this future date. New applications should not rely on the per-thread semantic of alarm(), since this semantic will become obsolete.

In a process linked with -lpthread (whether or not it is also linked with -lthread), the semantics of alarm() are per-process, i.e. the resulting SIGALRM is sent to the process, and not necessarily to the calling thread. This semantic will be supported in the future.

This semantic is obtainable by simply linking with -lpthread. One can continue to use Solaris thread interfaces by linking with both -lpthread and -lthread.

Return Values

alarm() returns the amount of time previously remaining in the alarm clock of the calling process.

See Also

exec(2) , fork(2) , pause(2) , signal(3C) , thr_sigsetmask(3T)


Table of Contents