xref: /openbsd-src/lib/libc/sys/getitimer.2 (revision 63bed618508e3fb99791c6a7f056726a0c37f899)
1.\"	$OpenBSD: getitimer.2,v 1.33 2019/06/24 21:20:12 schwarze Exp $
2.\"	$NetBSD: getitimer.2,v 1.6 1995/10/12 15:40:54 jtc Exp $
3.\"
4.\" Copyright (c) 1983, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)getitimer.2	8.2 (Berkeley) 12/11/93
32.\"
33.Dd $Mdocdate: June 24 2019 $
34.Dt GETITIMER 2
35.Os
36.Sh NAME
37.Nm getitimer ,
38.Nm setitimer
39.Nd get/set value of interval timer
40.Sh SYNOPSIS
41.In sys/time.h
42.Pp
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.In sys/time.h .
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-null).
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.
89Setting
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.
102A
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.
111A
112.Dv SIGVTALRM
113signal is 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.
119It is designed to be used by interpreters in statistically profiling
120the execution of interpreted programs.
121Each time the
122.Dv ITIMER_PROF
123timer expires, the
124.Dv SIGPROF
125signal is delivered.
126Because this signal may interrupt in-progress
127system calls, programs using this timer must be prepared to
128restart interrupted system calls.
129.Sh RETURN VALUES
130.Rv -std
131.Sh ERRORS
132.Fn getitimer
133and
134.Fn setitimer
135will fail if:
136.Bl -tag -width Er
137.It Bq Er EFAULT
138The
139.Fa value
140parameter specified a bad address.
141.It Bq Er EINVAL
142An unrecognized value for
143.Fa which
144was specified.
145.El
146.Pp
147In addition,
148.Fn setitimer
149may return the following error:
150.Bl -tag -width Er
151.It Bq Er EINVAL
152.Fa value
153or
154.Fa ovalue
155specified a time that was too large to be handled.
156.El
157.Sh SEE ALSO
158.Xr clock_gettime 2 ,
159.Xr gettimeofday 2 ,
160.Xr poll 2 ,
161.Xr select 2 ,
162.Xr sigaction 2
163.Sh STANDARDS
164The
165.Fn getitimer
166and
167.Fn setitimer
168functions conform to
169.St -p1003.1-2008 .
170.Sh HISTORY
171The
172.Fn getitimer
173and
174.Fn setitimer
175system calls first appeared in
176.Bx 4.1c .
177