HP-UX Reference (11i v2 07/12) - 2 System Calls (vol 5)
c
clocks(2) clocks(2)
RETURN VALUE
A return of 0 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.
[EFAULT] The
tp or res argument points to an invalid address.
EXAMPLES
Advance the system wide realtime clock approximately one hour:
#include <time.h>
#include <errno.h>
struct timespec cur_time, new_time;
if (clock_gettime(CLOCK_REALTIME, &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, &new_time)) {
perror("clock_settime(CLOCK_REALTIME) failed");
exit(2);
}
Get the resolution of the user profiling clock:
#include <time.h>
#include <errno.h>
struct timespec resolution;
if (clock_getres(CLOCK_PROFILE, &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), privileges(5).
STANDARDS CONFORMANCE
clock_getres():POSIX.4
clock_gettime():POSIX.4
clock_settime():POSIX.4
66 Hewlett-Packard Company − 2 − HP-UX 11i Version 2: December 2007 Update