1clock_settime(3C) Standard C Library Functions clock_settime(3C)
2
3
4
6 clock_settime, clock_gettime, clock_getres - high-resolution clock
7 operations
8
10 #include <time.h>
11
12 int clock_settime(clockid_t clock_id, const struct timespec *tp);
13
14
15 int clock_gettime(clockid_t clock_id, struct timespec *tp);
16
17
18 int clock_getres(clockid_t clock_id, struct timespec *res);
19
20
22 The clock_settime() function sets the specified clock, clock_id, to the
23 value specified by tp. Time values that are between two consecutive
24 non-negative integer multiples of the resolution of the specified clock
25 are truncated down to the smaller multiple of the resolution.
26
27
28 The clock_gettime() function returns the current value tp for the spec‐
29 ified clock, clock_id.
30
31
32 The resolution of any clock can be obtained by calling clock_getres().
33 Clock resolutions are system-dependent and cannot be set by a process.
34 If the argument res is not NULL, the resolution of the specified clock
35 is stored in the location pointed to by res. If res is NULL, the clock
36 resolution is not returned. If the time argument of clock_settime() is
37 not a multiple of res, then the value is truncated to a multiple of
38 res.
39
40
41 A clock may be systemwide (that is, visible to all processes) or per-
42 process (measuring time that is meaningful only within a process).
43
44
45 A clock_id of CLOCK_REALTIME is defined in <time.h>. This clock repre‐
46 sents the realtime clock for the system. For this clock, the values
47 returned by clock_gettime() and specified by clock_settime() represent
48 the amount of time (in seconds and nanoseconds) since the Epoch. Addi‐
49 tional clocks may also be supported. The interpretation of time values
50 for these clocks is unspecified.
51
52
53 A clock_id of CLOCK_HIGHRES represents the non-adjustable, high-resolu‐
54 tion clock for the system. For this clock, the value returned by
55 clock_gettime(3C) represents the amount of time (in seconds and
56 nanoseconds) since some arbitrary time in the past; it is not corre‐
57 lated in any way to the time of day, and thus is not subject to reset‐
58 ting or drifting by way of adjtime(2), ntp_adjtime(2), settimeof‐
59 day(3C), or clock_settime(). The time source for this clock is the
60 same as that for gethrtime(3C).
61
62
63 Additional clocks may also be supported. The interpretation of time
64 values for these clocks is unspecified.
65
67 Upon successful completion, 0 is returned. Otherwise, −1 is returned
68 and errno is set to indicate the error.
69
71 The clock_settime(), clock_gettime() and clock_getres() functions will
72 fail if:
73
74 EINVAL The clock_id argument does not specify a known clock.
75
76
77 ENOSYS The functions clock_settime(), clock_gettime(), and
78 clock_getres() are not supported by this implementation.
79
80
81
82 The clock_settime() function will fail if:
83
84 EINVAL The tp argument to clock_settime() is outside the range for
85 the given clock ID; or the tp argument specified a nanosecond
86 value less than zero or greater than or equal to 1000 mil‐
87 lion.
88
89
90
91 The clock_settime() function may fail if:
92
93 EPERM The requesting process does not have the appropriate privilege
94 to set the specified clock.
95
96
98 See attributes(5) for descriptions of the following attributes:
99
100
101
102
103 ┌─────────────────────────────┬─────────────────────────────────────┐
104 │ATTRIBUTE TYPE │ATTRIBUTE VALUE │
105 ├─────────────────────────────┼─────────────────────────────────────┤
106 │Interface Stability │Committed │
107 ├─────────────────────────────┼─────────────────────────────────────┤
108 │MT-Level │clock_gettime() is Async-Signal-Safe │
109 ├─────────────────────────────┼─────────────────────────────────────┤
110 │Standard │See standards(5). │
111 └─────────────────────────────┴─────────────────────────────────────┘
112
114 time(2), ctime(3C), gethrtime(3C), time.h(3HEAD), timer_gettime(3C),
115 attributes(5), standards(5)
116
117
118
119SunOS 5.11 5 Feb 2008 clock_settime(3C)