unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

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



 clocks(2)							   clocks(2)




 NAME
      clock_settime(), clock_gettime(), clock_getres() - clock operations

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

      int clock_settime(
	   clockid_t clock_id,
	   const struct timespec *tp
      );

      int clock_gettime(
	   clockid_t clock_id,
	   struct timespec *tp
      );

      int clock_getres(
	   clockid_t clock_id,
	   struct timespec *res
      );

 DESCRIPTION
    clock_settime()
      The clock_settime() function sets the specified clock, clock_id, to
      the value specified by tp.  Time values that are between two
      consecutive non-negative integer multiples of the resolution of the
      specified clock are truncated down to the smaller multiple of the
      resolution.

    clock_gettime()
      The clock_gettime() function returns the current value tp for the
      specified clock, clock_id.

    clock_getres()
      The resolution of any clock can be obtained by calling clock_getres().
      Clock resolutions are implementation defined and are not settable by a
      process.	If the argument res is not NULL, the resolution of the
      specified clock is stored into the location pointed to by res.  If res
      is NULL, the clock resolution is not returned.

      A clock may be system wide, that is, visible to all processes; or
      per-process, measuring time that is meaningful only within a process.

      The following clocks are supported:

	   CLOCK_REALTIME
		       This clock represents the realtime clock for the
		       system.	For this clock, the values returned by
		       clock_gettime() and specified by clock_settime()
		       represent the amount of time (in seconds and
		       nanoseconds) since the Epoch.  It is a system wide



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






 clocks(2)							   clocks(2)




		       clock.  Appropriate privileges are required to set
		       this clock.

	   CLOCK_VIRTUAL
		       This clock represents the amount of time (in seconds
		       and nanoseconds) that the calling process has spent
		       executing code in the user's context.  It is a per-
		       process clock.  It cannot be set by the user.

	   CLOCK_PROFILE
		       This clock represents the amount of time (in seconds
		       and nanoseconds) that the calling process has spent
		       executing code in both the user's context and in the
		       operating system on behalf of the calling process.
		       It is a per-process clock.  It cannot be set by the
		       user.

	   RTTIMER0 RTTIMER1
		       These clocks are high resolution hardware clocks
		       present on HP-RT realtime systems.  It is included
		       here so that applications accessing this hardware can
		       be compiled on HP-UX systems and then ported to an
		       HP-RT target.  HP-UX does not support RTTIMER0 or
		       RTTIMER1.

 RETURN VALUE
      A return of zero indicates that the call succeeded.  A return value of
      -1 indicates that an error occurred, and errno is set to indicate the
      error.

 ERRORS
      If any of the following conditions occur, the clock_settime(),
      clock_gettime(), and clock_getres() functions return -1 and set errno
      (see errno(2)) to the corresponding value:

	   [ENOSYS]    The functions clock_settime(), clock_gettime(), and
		       clock_getres() are not supported by this
		       implementation.

	   [EINVAL]    The clock_id argument does not specify a known clock.

	   [EINVAL]    The tp argument to clock_settime() is outside the
		       range for the given clock_id.

	   [EINVAL]    The tp argument specified a nanosecond value less
		       than zero or greater than or equal to 1000 million.

	   [EPERM]     The requesting process does not have the necessary
		       privileges to set the specified clock.





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






 clocks(2)							   clocks(2)




	   [EFAULT]    The tp or res argument points to an invalid address.

 EXAMPLES
      Advance the system wide realtime clock approximately one hour:

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

	   struct timespec cur_time, new_time;

	   if (clock_gettime(CLOCK_REALTIME, &&amp&amp&amp;cur_time)) {
		perror("clock_gettime(CLOCK_REALTIME) failed");
		exit(1);
	   }
	   new_time.tv_sec = cur_time.tv_sec + 3600;
	   new_time.tv_nsec = cur_time.tv_nsec;
	   if (clock_settime(CLOCK_REALTIME, &&amp&amp&amp;new_time)) {
		perror("clock_settime(CLOCK_REALTIME) failed");
		exit(2);
	   }

      Get the resolution of the user profiling clock:

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

	   struct timespec resolution;

	   if (clock_getres(CLOCK_PROFILE, &&amp&amp&amp;resolution)) {
		perror("clock_getres(CLOCK_PROFILE) failed");
		exit(1);
	   }
	   (void)printf("Resolution of user profiling clock is:\n");
	   (void)printf("%d seconds and %d nanoseconds.\n",
		     resolution.tv_sec, resolution.tv_nsec);

 AUTHOR
      clock_settime(), clock_gettime(), and clock_getres() were derived from
      the proposed IEEE POSIX P1003.4 Standard, Draft 14.

 SEE ALSO
      timers(2).

 STANDARDS CONFORMANCE
      clock_getres(): POSIX.4

      clock_gettime(): POSIX.4

      clock_settime(): POSIX.4





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






 clocks(2)							   clocks(2)























































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