Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
alarm(2)		      System Calls Manual		      alarm(2)

       alarm - set a process alarm clock

       #include	<unistd.h>

       unsigned	alarm(unsigned sec);


       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  (So-
       laris threads) and not with -lpthread (POSIX threads) currently behaves
       in the following	fashion:

       o if the	calling	thread is a bound thread, the resulting	SIGALRM	is de-
	 livered  to the bound thread's	LWP, i.e. to the calling thread. There
	 is a bug currently that this signal is	not maskable  via  thr_sigset-
	 mask(3T) on this bound	thread.

       o if  the calling thread	is an unbound thread, the resulting SIGALRM is
	 sent to the LWP on which the thread was running when  it  issued  the
	 call  to  alarm(). This is neither a per-process semantic, nor	a per-
	 thread	semantic, since	the LWP	could change threads after the call to
	 alarm() but before the	SIGALRM	delivery, causing some other thread to
	 get it	possibly. Hence	this is	basically a bug.

       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  re-
       sulting	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.

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

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

				  28 Mar 1995			      alarm(2)


Want to link to this manual page? Use this URL:

home | help