]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/sys/clock_gettime.2
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / sys / clock_gettime.2
1 .\"     $OpenBSD: clock_gettime.2,v 1.4 1997/05/08 20:21:16 kstailey Exp $
2 .\"
3 .\" Copyright (c) 1980, 1991, 1993
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\" 4. Neither the name of the University nor the names of its contributors
15 .\"    may be used to endorse or promote products derived from this software
16 .\"    without specific prior written permission.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" SUCH DAMAGE.
29 .\"
30 .\" $FreeBSD$
31 .\"
32 .Dd December 29, 2009
33 .Dt CLOCK_GETTIME 2
34 .Os
35 .Sh NAME
36 .Nm clock_gettime ,
37 .Nm clock_settime ,
38 .Nm clock_getres
39 .Nd get/set/calibrate date and time
40 .Sh LIBRARY
41 .Lb libc
42 .Sh SYNOPSIS
43 .In time.h
44 .Ft int
45 .Fn clock_gettime "clockid_t clock_id" "struct timespec *tp"
46 .Ft int
47 .Fn clock_settime "clockid_t clock_id" "const struct timespec *tp"
48 .Ft int
49 .Fn clock_getres "clockid_t clock_id" "struct timespec *tp"
50 .Sh DESCRIPTION
51 The
52 .Fn clock_gettime
53 and
54 .Fn clock_settime
55 system calls allow the calling process to retrieve or set the value
56 used by a clock which is specified by
57 .Fa clock_id .
58 .Pp
59 The
60 .Fa clock_id
61 argument
62 can be one of the following values:
63 .Dv CLOCK_REALTIME ,
64 .Dv CLOCK_REALTIME_PRECISE ,
65 .Dv CLOCK_REALTIME_FAST
66 for time that increments as
67 a wall clock should;
68 .Dv CLOCK_MONOTONIC ,
69 .Dv CLOCK_MONOTONIC_PRECISE ,
70 .Dv CLOCK_MONOTONIC_FAST
71 which increments in SI seconds;
72 .Dv CLOCK_UPTIME ,
73 .Dv CLOCK_UPTIME_PRECISE ,
74 .Dv CLOCK_UPTIME_FAST
75 which starts at zero when the kernel boots and increments
76 monotonically in SI seconds while the machine is running;
77 .Dv CLOCK_VIRTUAL
78 for time that increments only when
79 the CPU is running in user mode on behalf of the calling process;
80 .Dv CLOCK_PROF
81 for time that increments when the CPU is running in user or
82 kernel mode; or
83 .Dv CLOCK_SECOND
84 which returns the current second without performing a full time counter
85 query, using in-kernel cached value of current second.
86 .Pp
87 The clock IDs
88 .Fa CLOCK_REALTIME_FAST ,
89 .Fa CLOCK_MONOTONIC_FAST ,
90 .Fa CLOCK_UPTIME_FAST
91 are analogs of corresponding IDs without _FAST suffix but do not perform
92 a full time counter query, so their accuracy is one timer tick.
93 Similarly,
94 .Fa CLOCK_REALTIME_PRECISE ,
95 .Fa CLOCK_MONOTONIC_PRECISE ,
96 .Fa CLOCK_UPTIME_PRECISE
97 are used to get the most exact value as possible, at the expense of
98 execution time.
99 .Pp
100 The structure pointed to by
101 .Fa tp
102 is defined in
103 .In sys/timespec.h
104 as:
105 .Bd -literal
106 struct timespec {
107         time_t  tv_sec;         /* seconds */
108         long    tv_nsec;        /* and nanoseconds */
109 };
110 .Ed
111 .Pp
112 Only the super-user may set the time of day, using only
113 .Fa CLOCK_REALTIME .
114 If the system securelevel is greater than 1 (see
115 .Xr init 8 ) ,
116 the time may only be advanced.
117 This limitation is imposed to prevent a malicious super-user
118 from setting arbitrary time stamps on files.
119 The system time can still be adjusted backwards using the
120 .Xr adjtime 2
121 system call even when the system is secure.
122 .Pp
123 The resolution (granularity) of a clock is returned by the
124 .Fn clock_getres
125 system call.
126 This value is placed in a (non-NULL)
127 .Fa *tp .
128 .Sh RETURN VALUES
129 .Rv -std
130 .Sh ERRORS
131 The following error codes may be set in
132 .Va errno :
133 .Bl -tag -width Er
134 .It Bq Er EINVAL
135 The
136 .Fa clock_id
137 argument
138 was not a valid value.
139 .It Bq Er EFAULT
140 The
141 .Fa *tp
142 argument address referenced invalid memory.
143 .It Bq Er EPERM
144 A user other than the super-user attempted to set the time.
145 .El
146 .Sh SEE ALSO
147 .Xr date 1 ,
148 .Xr adjtime 2 ,
149 .Xr ctime 3 ,
150 .Xr timed 8
151 .Sh STANDARDS
152 The
153 .Fn clock_gettime ,
154 .Fn clock_settime ,
155 and
156 .Fn clock_getres
157 system calls conform to
158 .St -p1003.1b-93 .
159 The clock IDs
160 .Fa CLOCK_REALTIME_FAST ,
161 .Fa CLOCK_REALTIME_PRECISE ,
162 .Fa CLOCK_MONOTONIC_FAST ,
163 .Fa CLOCK_MONOTONIC_PRECISE ,
164 .Fa CLOCK_UPTIME ,
165 .Fa CLOCK_UPTIME_FAST ,
166 .Fa CLOCK_UPTIME_PRECISE ,
167 .Fa CLOCK_SECOND
168 are FreeBSD extensions to the POSIX interface.