xref: /freebsd/lib/libsys/getitimer.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\" Copyright (c) 1983, 1991, 1993
2*8269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
10*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
11*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
13*8269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
14*8269e767SBrooks Davis.\"    without specific prior written permission.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8269e767SBrooks Davis.\" SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.Dd May 1, 2020
29*8269e767SBrooks Davis.Dt GETITIMER 2
30*8269e767SBrooks Davis.Os
31*8269e767SBrooks Davis.Sh NAME
32*8269e767SBrooks Davis.Nm getitimer ,
33*8269e767SBrooks Davis.Nm setitimer
34*8269e767SBrooks Davis.Nd get/set value of interval timer
35*8269e767SBrooks Davis.Sh LIBRARY
36*8269e767SBrooks Davis.Lb libc
37*8269e767SBrooks Davis.Sh SYNOPSIS
38*8269e767SBrooks Davis.In sys/time.h
39*8269e767SBrooks Davis.Fd "#define ITIMER_REAL      0"
40*8269e767SBrooks Davis.Fd "#define ITIMER_VIRTUAL   1"
41*8269e767SBrooks Davis.Fd "#define ITIMER_PROF      2"
42*8269e767SBrooks Davis.Ft int
43*8269e767SBrooks Davis.Fn getitimer "int which" "struct itimerval *value"
44*8269e767SBrooks Davis.Ft int
45*8269e767SBrooks Davis.Fn setitimer "int which" "const struct itimerval *value" "struct itimerval *ovalue"
46*8269e767SBrooks Davis.Sh DESCRIPTION
47*8269e767SBrooks DavisThe system provides each process with three interval timers,
48*8269e767SBrooks Davisdefined in
49*8269e767SBrooks Davis.In sys/time.h .
50*8269e767SBrooks DavisThe
51*8269e767SBrooks Davis.Fn getitimer
52*8269e767SBrooks Davissystem call returns the current value for the timer specified in
53*8269e767SBrooks Davis.Fa which
54*8269e767SBrooks Davisin the structure at
55*8269e767SBrooks Davis.Fa value .
56*8269e767SBrooks DavisThe
57*8269e767SBrooks Davis.Fn setitimer
58*8269e767SBrooks Davissystem call sets a timer to the specified
59*8269e767SBrooks Davis.Fa value
60*8269e767SBrooks Davis(returning the previous value of the timer if
61*8269e767SBrooks Davis.Fa ovalue
62*8269e767SBrooks Davisis not a null pointer).
63*8269e767SBrooks Davis.Pp
64*8269e767SBrooks DavisA timer value is defined by the
65*8269e767SBrooks Davis.Fa itimerval
66*8269e767SBrooks Davisstructure:
67*8269e767SBrooks Davis.Bd -literal -offset indent
68*8269e767SBrooks Davisstruct itimerval {
69*8269e767SBrooks Davis	struct	timeval it_interval;	/* timer interval */
70*8269e767SBrooks Davis	struct	timeval it_value;	/* current value */
71*8269e767SBrooks Davis};
72*8269e767SBrooks Davis.Ed
73*8269e767SBrooks Davis.Pp
74*8269e767SBrooks DavisIf
75*8269e767SBrooks Davis.Fa it_value
76*8269e767SBrooks Davisis non-zero, it indicates the time to the next timer expiration.
77*8269e767SBrooks DavisIf
78*8269e767SBrooks Davis.Fa it_interval
79*8269e767SBrooks Davisis non-zero, it specifies a value to be used in reloading
80*8269e767SBrooks Davis.Fa it_value
81*8269e767SBrooks Daviswhen the timer expires.
82*8269e767SBrooks DavisSetting
83*8269e767SBrooks Davis.Fa it_value
84*8269e767SBrooks Davisto 0 disables a timer, regardless of the value of
85*8269e767SBrooks Davis.Fa it_interval .
86*8269e767SBrooks DavisSetting
87*8269e767SBrooks Davis.Fa it_interval
88*8269e767SBrooks Davisto 0 causes a timer to be disabled after its next expiration (assuming
89*8269e767SBrooks Davis.Fa it_value
90*8269e767SBrooks Davisis non-zero).
91*8269e767SBrooks Davis.Pp
92*8269e767SBrooks DavisTime values smaller than the resolution of the
93*8269e767SBrooks Davissystem clock are rounded up to this resolution
94*8269e767SBrooks Davis(typically 10 milliseconds).
95*8269e767SBrooks Davis.Pp
96*8269e767SBrooks DavisThe
97*8269e767SBrooks Davis.Dv ITIMER_REAL
98*8269e767SBrooks Davistimer decrements in real time.
99*8269e767SBrooks DavisA
100*8269e767SBrooks Davis.Dv SIGALRM
101*8269e767SBrooks Davissignal is
102*8269e767SBrooks Davisdelivered when this timer expires.
103*8269e767SBrooks Davis.Pp
104*8269e767SBrooks DavisThe
105*8269e767SBrooks Davis.Dv ITIMER_VIRTUAL
106*8269e767SBrooks Davistimer decrements in process virtual time.
107*8269e767SBrooks DavisIt runs only when the process is executing.
108*8269e767SBrooks DavisA
109*8269e767SBrooks Davis.Dv SIGVTALRM
110*8269e767SBrooks Davissignal
111*8269e767SBrooks Davisis delivered when it expires.
112*8269e767SBrooks Davis.Pp
113*8269e767SBrooks DavisThe
114*8269e767SBrooks Davis.Dv ITIMER_PROF
115*8269e767SBrooks Davistimer decrements both in process virtual time and
116*8269e767SBrooks Daviswhen the system is running on behalf of the process.
117*8269e767SBrooks DavisIt is designed
118*8269e767SBrooks Davisto be used by interpreters in statistically profiling the execution
119*8269e767SBrooks Davisof interpreted programs.
120*8269e767SBrooks DavisEach time the
121*8269e767SBrooks Davis.Dv ITIMER_PROF
122*8269e767SBrooks Davistimer expires, the
123*8269e767SBrooks Davis.Dv SIGPROF
124*8269e767SBrooks Davissignal is
125*8269e767SBrooks Davisdelivered.
126*8269e767SBrooks DavisBecause this signal may interrupt in-progress
127*8269e767SBrooks Davissystem calls, programs using this timer must be prepared to
128*8269e767SBrooks Davisrestart interrupted system calls.
129*8269e767SBrooks Davis.Pp
130*8269e767SBrooks DavisThe maximum number of seconds allowed for
131*8269e767SBrooks Davis.Fa it_interval
132*8269e767SBrooks Davisand
133*8269e767SBrooks Davis.Fa it_value
134*8269e767SBrooks Davisin
135*8269e767SBrooks Davis.Fn setitimer
136*8269e767SBrooks Davisis 100000000.
137*8269e767SBrooks Davis.Sh NOTES
138*8269e767SBrooks DavisThree macros for manipulating time values are defined in
139*8269e767SBrooks Davis.In sys/time.h .
140*8269e767SBrooks DavisThe
141*8269e767SBrooks Davis.Fn timerclear
142*8269e767SBrooks Davismacro
143*8269e767SBrooks Davissets a time value to zero,
144*8269e767SBrooks Davis.Fn timerisset
145*8269e767SBrooks Davistests if a time value is non-zero, and
146*8269e767SBrooks Davis.Fn timercmp
147*8269e767SBrooks Daviscompares two time values.
148*8269e767SBrooks Davis.Sh RETURN VALUES
149*8269e767SBrooks Davis.Rv -std
150*8269e767SBrooks Davis.Sh ERRORS
151*8269e767SBrooks DavisThe
152*8269e767SBrooks Davis.Fn getitimer
153*8269e767SBrooks Davisand
154*8269e767SBrooks Davis.Fn setitimer
155*8269e767SBrooks Davissystem calls
156*8269e767SBrooks Daviswill fail if:
157*8269e767SBrooks Davis.Bl -tag -width Er
158*8269e767SBrooks Davis.It Bq Er EFAULT
159*8269e767SBrooks DavisThe
160*8269e767SBrooks Davis.Fa value
161*8269e767SBrooks Davisargument specified a bad address.
162*8269e767SBrooks Davis.It Bq Er EINVAL
163*8269e767SBrooks DavisThe
164*8269e767SBrooks Davis.Fa value
165*8269e767SBrooks Davisargument specified a time that was too large
166*8269e767SBrooks Davisto be handled.
167*8269e767SBrooks Davis.El
168*8269e767SBrooks Davis.Sh SEE ALSO
169*8269e767SBrooks Davis.Xr gettimeofday 2 ,
170*8269e767SBrooks Davis.Xr select 2 ,
171*8269e767SBrooks Davis.Xr sigaction 2 ,
172*8269e767SBrooks Davis.Xr clocks 7
173*8269e767SBrooks Davis.Sh STANDARDS
174*8269e767SBrooks DavisThe
175*8269e767SBrooks Davis.Fn getitimer
176*8269e767SBrooks Davisand
177*8269e767SBrooks Davis.Fn setitimer
178*8269e767SBrooks Davisfunctions conform to
179*8269e767SBrooks Davis.St -p1003.1-2001 .
180*8269e767SBrooks DavisThe later
181*8269e767SBrooks Davis.St -p1003.1-2008
182*8269e767SBrooks Davisrevision however marked both functions as obsolescent,
183*8269e767SBrooks Davisrecommending the use of
184*8269e767SBrooks Davis.Xr timer_gettime 2
185*8269e767SBrooks Davisand
186*8269e767SBrooks Davis.Xr timer_settime 2
187*8269e767SBrooks Davisinstead.
188*8269e767SBrooks Davis.Sh HISTORY
189*8269e767SBrooks DavisThe
190*8269e767SBrooks Davis.Fn getitimer
191*8269e767SBrooks Davissystem call appeared in
192*8269e767SBrooks Davis.Bx 4.2 .
193