xref: /freebsd-13.1/lib/libc/sys/getitimer.2 (revision 422ff090)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)getitimer.2	8.3 (Berkeley) 5/16/95
33.\"
34.Dd May 16, 1995
35.Dt GETITIMER 2
36.Os BSD 4.2
37.Sh NAME
38.Nm getitimer ,
39.Nm setitimer
40.Nd get/set value of interval timer
41.Sh SYNOPSIS
42.Fd #include <sys/time.h>
43.Fd #define ITIMER_REAL		0
44.Fd #define ITIMER_VIRTUAL	1
45.Fd #define ITIMER_PROF		2
46.Ft int
47.Fn getitimer "int which" "struct itimerval *value"
48.Ft int
49.Fn setitimer "int which" "const struct itimerval *value" "struct itimerval *ovalue"
50.Sh DESCRIPTION
51The system provides each process with three interval timers,
52defined in
53.Ao Pa sys/time.h Ac .
54The
55.Fn getitimer
56call returns the current value for the timer specified in
57.Fa which
58in the structure at
59.Fa value .
60The
61.Fn setitimer
62call sets a timer to the specified
63.Fa value
64(returning the previous value of the timer if
65.Fa ovalue
66is non-nil).
67.Pp
68A timer value is defined by the
69.Fa itimerval
70structure:
71.Bd -literal -offset indent
72struct itimerval {
73	struct	timeval it_interval;	/* timer interval */
74	struct	timeval it_value;	/* current value */
75};
76.Ed
77.Pp
78If
79.Fa it_value
80is non-zero, it indicates the time to the next timer expiration.
81If
82.Fa it_interval
83is non-zero, it specifies a value to be used in reloading
84.Fa it_value
85when the timer expires.
86Setting
87.Fa it_value
88to 0 disables a timer, regardless of the value of
89.Fa it_interval .
90Setting
91.Fa it_interval
92to 0 causes a timer to be disabled after its next expiration (assuming
93.Fa it_value
94is non-zero).
95.Pp
96Time values smaller than the resolution of the
97system clock are rounded up to this resolution
98(typically 10 milliseconds).
99.Pp
100The
101.Dv ITIMER_REAL
102timer decrements in real time.  A
103.Dv SIGALRM
104signal is
105delivered when this timer expires.
106.Pp
107The
108.Dv ITIMER_VIRTUAL
109timer decrements in process virtual time.
110It runs only when the process is executing.  A
111.Dv SIGVTALRM
112signal
113is delivered when it expires.
114.Pp
115The
116.Dv ITIMER_PROF
117timer decrements both in process virtual time and
118when the system is running on behalf of the process.  It is designed
119to be used by interpreters in statistically profiling the execution
120of interpreted programs.
121Each time the
122.Dv ITIMER_PROF
123timer expires, the
124.Dv SIGPROF
125signal is
126delivered.  Because this signal may interrupt in-progress
127system calls, programs using this timer must be prepared to
128restart interrupted system calls.
129.Pp
130The maximum number of seconds allowed for
131.Fa it_interval
132and
133.Fa it_value
134in
135.Fn setitimer
136is 100000000.
137.Sh NOTES
138Three macros for manipulating time values are defined in
139.Ao Pa sys/time.h Ac .
140.Fa Timerclear
141sets a time value to zero,
142.Fa timerisset
143tests if a time value is non-zero, and
144.Fa timercmp
145compares two time values.
146.Sh RETURN VALUES
147If the calls succeed, a value of 0 is returned.  If an error occurs,
148the value -1 is returned, and a more precise error code is placed
149in the global variable
150.Va errno .
151.Sh ERRORS
152.Fn Getitimer
153and
154.Fn setitimer
155will fail if:
156.Bl -tag -width Er
157.It Bq Er EFAULT
158The
159.Fa value
160parameter specified a bad address.
161.It Bq Er EINVAL
162A
163.Fa value
164parameter specified a time that was too large
165to be handled.
166.El
167.Sh SEE ALSO
168.Xr gettimeofday 2 ,
169.Xr select 2 ,
170.Xr sigvec 2 ,
171.Xr clocks 7
172.Sh HISTORY
173The
174.Fn getitimer
175function call appeared in
176.Bx 4.2 .
177