unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (HP-UX-11.11)
Page:
Section:
Apropos / Subsearch:
optional field



 timers(2)							   timers(2)




 NAME
      timer_create(), timer_delete(), timer_settime(), timer_gettime(),
      timer_getoverrun() - timer operations

 SYNOPSIS
      #include <&lt&lt&lt;time.h>&gt&gt&gt;

      int timer_create(
	   clockid_t clock_id,
	   struct sigevent *evp,
	   timer_t *timerid
      );

      int timer_delete(
	   timer_t timerid
      );

      int timer_settime(
	   timer_t timerid,
	   int flags,
	   const struct itimerspec *value,
	   struct itimerspec *ovalue
      );

      int timer_gettime(
	   timer_t timerid,
	   struct itimerspec *value
      );

      int timer_getoverrun(
	   timer_t timerid
      );

 DESCRIPTION
    timer_create()
      The timer_create() function creates a per-process timer using the
      specified clock, clock_id, as the timing base.  The timer_create()
      function returns, in the location referenced by timerid, a timer ID of
      type timer_t used to identify the timer in timer requests.  This timer
      ID will be unique within the calling process until the timer is
      deleted.	The particular clock, clock_id, is defined in <&lt&lt&lt;time.h>&gt&gt&gt;.	 The
      timer whose ID is returned will be in a disarmed state upon return
      from timer_create().

      The evp argument, if non-NULL, points to a sigevent structure.  If the
      sigev_notify member of evp is SIGEV_SIGNAL, then the structure should
      also specify the signal number to be sent to the process on timer
      expiration. The signal to be sent is specified in the sigev_signo
      field of evp.  If the sigev_notify member of evp is SIGEV_NONE, no
      notification is sent. If evp is NULL, then a default signal is sent to
      the process.  The defaults for the clocks CLOCK_REALTIME,



 Hewlett-Packard Company	    - 1 -   HP-UX Release 11i: November 2000






 timers(2)							   timers(2)




      CLOCK_VIRTUAL, and CLOCK_PROFILE are SIGALRM, SIGVTALRM, and SIGPROF.

      Per-process timers are not inherited by a child process across a
      fork() and are disarmed and deleted by an exec().

    timer_delete()
      The timer_delete() function deletes the specified timer, timerid,
      previously created by the timer_create() function.  If the timer is
      armed when timer_delete() is called, the behavior is as if the timer
      is automatically disarmed before removal.	 Any pending notifications
      from the timer remain.

    timer_settime()
      The timer_settime() function sets the time until the next expiration
      of the timer specified by timerid from the it_value member of the
      value argument and arms the timer if the it_value member of value is
      non-zero.	 If the specified timer was already armed when
      timer_settime() is called, this call resets the time until next
      expiration to the value specified.  If the it_value member of value is
      zero, the timer is disarmed.  Any pending notifications from the timer
      remain.

      If the flag TIMER_ABSTIME is not set in the argument flags,
      timer_settime() behaves as if the time until next expiration is set
      equal to the interval specified by the it_value member of value.	That
      is, the timer will expire in it_value nanoseconds from when the call
      is made.

      If the flag TIMER_ABSTIME is set in the argument flags,
      timer_settime() behaves as if the time until next expiration is set
      equal to the difference between the absolute time specified by the
      it_value member of value and the current value of the clock associated
      with timerid.  That is, the timer will expire when the clock reaches
      the value specified by the it_value member of value.  If the specified
      time has already passed, the function will succeed and the expiration
      notification is made.

      The reload value of the timer is set to the value specified by the
      it_interval member of value.  When a timer is armed with a non-zero
      it_interval, a periodic (or repetitive) timer is specified.

      Time values that are between two consecutive non-negative integer
      multiples of the resolution of the specified timer are rounded up to
      the larger multiple of the resolution.  A quantization error will not
      cause the timer to expire earlier than the rounded-up time value.

      If the argument ovalue is not NULL, the function timer_settime()
      stores, in the location referenced by ovalue, a value representing the
      previous amount of time before the timer would have expired or zero if
      the timer was disarmed, together with the previous timer reload value.
      The members of ovalue are subject to the resolution of the timer, and



 Hewlett-Packard Company	    - 2 -   HP-UX Release 11i: November 2000






 timers(2)							   timers(2)




      are the same values that would be returned by a timer_gettime() call
      at that point in time.

    timer_gettime()
      The timer_gettime() function stores the amount of time until the
      specified timer, timerid, expires and the timer's reload value into
      the space pointed to by the value argument.  The it_value member of
      this structure will contain the amount of time before the timer
      expires, or zero if the timer is disarmed.  This value is returned as
      the interval until timer expiration, even if the timer was armed with
      absolute time.  The it_interval member of value will contain the
      reload value last set by timer_settime().

    timer_getoverrun()
      Only a single signal is delivered to the process for a given timer at
      any point in time.  When a timer for which a signal is still pending
      expires, no signal is delivered, and a timer overrun has occurred.
      When a timer expiration signal is delivered to a process, the
      timer_getoverrun() function returns the timer expiration count for the
      specified timer.	The overrun count returned contains the number of
      extra timer expirations which occurred between the time the signal was
      generated and when it was delivered, up to but not including an
      implementation defined maximum of DELAYTIMER_MAX.	 If the number of
      such extra expirations is greater than or equal to DELAYTIMER_MAX,
      then the overrun count is set to DELAYTIMER_MAX.	The value returned
      by timer_getoverrun() applies to the most recent expiration signal
      delivery for the timer.  If no expiration signal has been delivered
      for the timer, the meaning of the overrun count returned is undefined.

 RETURN VALUE
      Upon successful completion, timer_create() returns zero and updates
      the location referenced by timerid to a timer_t which can be passed to
      the per-process timer calls.  Otherwise, timer_create() returns -1 and
      sets errno to indicate the error.	 The value of timerid is undefined
      if an error occurs.

      Upon successful completion, timer_delete() returns zero.	Otherwise,
      timer_delete() returns -1 and sets errno to indicate the error.

      Upon successful completion, timer_settime() returns zero and updates
      the location referenced by ovalue, if ovalue is non-NULL.

      Upon successful completion, timer_gettime() returns zero and updates
      the location referenced by value, if ovalue is non-NULL.	Otherwise,
      timer_gettime() returns -1 and sets errno to indicate the error.

      Upon successful completion, timer_getoverrun() returns the timer
      expiration overrun count as explained above.  Otherwise,
      timer_getoverrun() returns -1 and sets errno to indicate the error.





 Hewlett-Packard Company	    - 3 -   HP-UX Release 11i: November 2000






 timers(2)							   timers(2)




 ERRORS
      If any of the following conditions occur, the timer_create() function
      returns -1 and sets errno (see errno(2)) to the corresponding value:

	   [EAGAIN]    The system lacks sufficient signal queuing resources
		       to honor the request.

	   [EAGAIN]    The calling process has already created all of the
		       timers it is allowed by this implementation.

	   [EINVAL]    The specified clock ID is not defined.

	   [EFAULT]    The timerid or evp argument points to an invalid
		       address.

	   [ENOSYS]    The function timer_create() is not supported by this
		       implementation.

      If any of the following conditions occur, the timer_delete() function
      returns -1 and sets errno to the corresponding value:

	   [EINVAL]    The timer ID specified by timerid is not a valid
		       timer ID.

	   [ENOSYS]    The function timer_delete() is not supported by this
		       implementation.

      If any of the following conditions occur, the timer_settime(),
      timer_gettime(), and timer_getoverrun() functions return -1 and set
      errno to the corresponding value:

	   [EINVAL]    The timerid argument does not correspond to an ID
		       returned by timer_create(), but not yet deleted by
		       timer_delete().

	   [EINVAL]    The value structure passed to timer_settime()
		       specified a nanosecond value less than zero or
		       greater than or equal to 1000 million.

	   [EFAULT]    The value or ovalue argument points to an invalid
		       address.

	   [ENOSYS]    The timer_settime(), timer_gettime(), and
		       timer_getoverrun() functions are not supported by
		       this implementation.

 EXAMPLES
      Create a timer, set it to go off in one minute, and deliver a SIGUSR1
      signal:





 Hewlett-Packard Company	    - 4 -   HP-UX Release 11i: November 2000






 timers(2)							   timers(2)




	   #include <&lt&lt&lt;signal.h>&gt&gt&gt;
	   #include <&lt&lt&lt;time.h>&gt&gt&gt;

	   timer_t timerid;
	   struct itimerspec one_minute = { {60, 0}, {0, 0} } ;

	   void handler()
	   {
		int overrun = timer_getoverrun(timerid);

		if (overrun == -1) {
		     perror("handler: timer_getoverrun()");
		     exit(1);
		}
		(void)printf("Timer expired, overrun count was %d,
			  overrun);
	   }

	   int main()
	   {
		struct sigaction sigact;
		struct sigevent sigev;

		sigact.sa_handler = handler;
		sigemptyset(sigact.sa_mask);
		sigact.sa_flags = 0;

		if (sigaction(SIGUSR1, &&amp&amp&amp;sigact, (struct sigaction *)NULL)
		     == -1) {
		     perror("sigaction");
		     exit(1);
		}

		sigev.sigev_notify = SIGEV_SIGNAL;
		sigev.sigev_signo = SIGUSR1;

		if (timer_create(CLOCK_REALTIME, &&amp&amp&amp;sigev, &&amp&amp&amp;timerid)
		     == -1) {
		     perror("timer_create");
		     exit(1);
		}

		if (timer_settime(timerid, 0, &&amp&amp&amp;one_minute, (struct itimerspec
		     == -1) {
		     perror("timer_create");
		     exit(1);
		}

		pause();
		if (timer_delete(timerid) == -1) {
		     perror("timer_delete");



 Hewlett-Packard Company	    - 5 -   HP-UX Release 11i: November 2000






 timers(2)							   timers(2)




		     exit(1);
		}
		return 0;
	   }

 AUTHOR
      timer_create(), timer_delete(), timer_settime(), timer_gettime(), and
      timer_getoverrun() were derived from the proposed IEEE POSIX P1003.4
      standard, draft 14.

 SEE ALSO
      clocks(2), getitimer(2).

 STANDARDS CONFORMANCE
      timer_create(): POSIX.4

      timer_delete(): POSIX.4

      timer_getoverrun(): POSIX.4

      timer_gettime(): POSIX.4

      timer_settime(): POSIX.4































 Hewlett-Packard Company	    - 6 -   HP-UX Release 11i: November 2000