United States-English |
|
|
HP-UX Reference > Cclocks(2)HP-UX 11i Version 3: February 2007 |
|
NAMEclock_settime(), clock_gettime(), clock_getres() — clock operations SYNOPSIS#include <time.h> 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); DESCRIPTIONclock_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:
RETURN VALUEA 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. ERRORSIf 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:
EXAMPLESAdvance 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); |
Printable version | ||
|