xref: /netbsd-src/lib/libc/sys/getitimer.2 (revision d9158b13b5dfe46201430699a3f7a235ecf28df3)
1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
2.\" 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.\"     from: @(#)getitimer.2	6.6 (Berkeley) 3/10/91
33.\"	$Id: getitimer.2,v 1.3 1993/11/25 00:38:54 jtc Exp $
34.\"
35.Dd March 10, 1991
36.Dt GETITIMER 2
37.Os BSD 4.2
38.Sh NAME
39.Nm getitimer ,
40.Nm setitimer
41.Nd get/set value of interval timer
42.Sh SYNOPSIS
43.Fd #include <sys/time.h>
44.Fd #define ITIMER_REAL		0
45.Fd #define ITIMER_VIRTUAL	1
46.Fd #define ITIMER_PROF		2
47.Ft int
48.Fn getitimer "int which" "struct itimerval *value"
49.Ft int
50.Fn setitimer "int which" "struct itimerval *value" "struct itimerval *ovalue"
51.Sh DESCRIPTION
52The system provides each process with three interval timers,
53defined in
54.Ao Pa sys/time.h Ac .
55The
56.Fn getitimer
57call returns the current value for the timer specified in
58.Fa which
59in the structure at
60.Fa value .
61The
62.Fn setitimer
63call sets a timer to the specified
64.Fa value
65(returning the previous value of the timer if
66.Fa ovalue
67is non-nil).
68.Pp
69A timer value is defined by the
70.Fa itimerval
71structure:
72.Bd -literal -offset indent
73struct itimerval {
74	struct	timeval it_interval;	/* timer interval */
75	struct	timeval it_value;	/* current value */
76};
77.Ed
78.Pp
79If
80.Fa it_value
81is non-zero, it indicates the time to the next timer expiration.
82If
83.Fa it_interval
84is non-zero, it specifies a value to be used in reloading
85.Fa it_value
86when the timer expires.
87Setting
88.Fa it_value
89to 0 disables a timer.  Setting
90.Fa it_interval
91to 0 causes a timer to be disabled after its next expiration (assuming
92.Fa it_value
93is non-zero).
94.Pp
95Time values smaller than the resolution of the
96system clock are rounded up to this resolution
97(typically 10 milliseconds).
98.Pp
99The
100.Dv ITIMER_REAL
101timer decrements in real time.  A
102.Dv SIGALRM
103signal is
104delivered when this timer expires.
105.Pp
106The
107.Dv ITIMER_VIRTUAL
108timer decrements in process virtual time.
109It runs only when the process is executing.  A
110.Dv SIGVTALRM
111signal
112is delivered when it expires.
113.Pp
114The
115.Dv ITIMER_PROF
116timer decrements both in process virtual time and
117when the system is running on behalf of the process.  It is designed
118to be used by interpreters in statistically profiling the execution
119of interpreted programs.
120Each time the
121.Dv ITIMER_PROF
122timer expires, the
123.Dv SIGPROF
124signal is
125delivered.  Because this signal may interrupt in-progress
126system calls, programs using this timer must be prepared to
127restart interrupted system calls.
128.Sh NOTES
129Three macros for manipulating time values are defined in
130.Ao Pa sys/time.h Ac .
131.Fa Timerclear
132sets a time value to zero,
133.Fa timerisset
134tests if a time value is non-zero, and
135.Fa timercmp
136compares two time values (beware that >= and <= do not
137work with this macro).
138.Sh RETURN VALUES
139If the calls succeed, a value of 0 is returned.  If an error occurs,
140the value -1 is returned, and a more precise error code is placed
141in the global variable
142.Va errno .
143.Sh ERRORS
144.Fn Getitimer
145and
146.Fn setitimer
147will fail if:
148.Bl -tag -width Er
149.It Bq Er EFAULT
150The
151.Fa value
152parameter specified a bad address.
153.It Bq Er EINVAL
154A
155.Fa value
156parameter specified a time was too large
157to be handled.
158.El
159.Sh SEE ALSO
160.Xr select 2 ,
161.Xr sigvec 2 ,
162.Xr gettimeofday 2
163.Sh HISTORY
164The
165.Fn getitimer
166function call appeared in
167.Bx 4.2 .
168