xref: /netbsd-src/lib/libc/sys/getitimer.2 (revision 46f5119e40af2e51998f686b2fdcc76b5488f7f3)
1.\"	$NetBSD: getitimer.2,v 1.26 2011/05/02 17:14:20 jruoho Exp $
2.\"
3.\" Copyright (c) 1983, 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.\" 3. 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.\"     @(#)getitimer.2	8.3 (Berkeley) 5/16/95
31.\"
32.Dd May 2, 2011
33.Dt GETITIMER 2
34.Os
35.Sh NAME
36.Nm getitimer ,
37.Nm setitimer
38.Nd get/set value of interval timer
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/time.h
43.Ft int
44.Fn getitimer "int which" "struct itimerval *value"
45.Ft int
46.Fn setitimer "int which" "const struct itimerval * restrict value" "struct itimerval * restrict ovalue"
47.Sh DESCRIPTION
48The system provides each process with three interval timers,
49defined in
50.Ao Pa sys/time.h Ac .
51The
52.Fn getitimer
53call returns the current value for the timer specified in
54.Fa which
55in the structure at
56.Fa value .
57The
58.Fn setitimer
59call sets a timer to the specified
60.Fa value ,
61returning the previous value of the timer if
62.Fa ovalue
63is not
64.Dv NULL .
65.Pp
66A timer value is defined by the
67.Fa itimerval
68structure:
69.Bd -literal -offset indent
70struct itimerval {
71	struct	timeval it_interval;	/* timer interval */
72	struct	timeval it_value;	/* current value */
73};
74.Ed
75.Pp
76If
77.Fa it_value
78is non-zero, it indicates the time to the next timer expiration.
79If
80.Fa it_interval
81is non-zero, it specifies a value to be used in reloading
82.Fa it_value
83when the timer expires.
84Setting
85.Fa it_value
86to 0 disables a timer.
87Setting
88.Fa it_interval
89to 0 causes a timer to be disabled after its next expiration (assuming
90.Fa it_value
91is non-zero).
92.Pp
93The
94.Fa which
95parameter specifies the type of the timer:
96.Bl -tag -width "ITIMER_VIRTUAL " -offset indent
97.It Dv ITIMER_REAL
98timer decrements in real time.
99A
100.Dv SIGALRM
101signal is
102delivered when this timer expires.
103.It Dv ITIMER_VIRTUAL
104timer decrements in process virtual time.
105It runs only when the process is executing.
106A
107.Dv SIGVTALRM
108signal
109is delivered when it expires.
110.It Dv ITIMER_PROF
111timer decrements both in process virtual time and
112when the system is running on behalf of the process.
113It is designed to be used by interpreters in statistically profiling
114the execution of interpreted programs.
115Each time the
116.Dv ITIMER_PROF
117timer expires, the
118.Dv SIGPROF
119signal is
120delivered.
121Because this signal may interrupt in-progress
122system calls, programs using this timer must be prepared to
123restart interrupted system calls.
124.El
125Note that:
126.Bl -bullet -offset indent
127.It
128Time values smaller than the resolution of the
129system clock are rounded up to this resolution
130(typically 10 milliseconds).
131.It
132The interaction between
133.Fn setitimer
134and
135.Xr alarm 3
136or
137.Xr sleep 3
138is unspecified by the specification.
139.El
140.Sh RETURN VALUES
141If the calls succeed, a value of 0 is returned.
142If an error occurs, the value \-1 is returned, and a more precise error
143code is placed in the global variable
144.Va errno .
145.Sh ERRORS
146Both functions may fail if:
147.Bl -tag -width Er
148.It Bq Er EFAULT
149The
150.Fa value
151parameter specified a bad address.
152.It Bq Er EINVAL
153A
154.Fa value
155parameter specified a time that was too large
156to be handled.
157.El
158.Sh SEE ALSO
159.Xr gettimeofday 2 ,
160.Xr select 2 ,
161.Xr sigaction 2 ,
162.Xr itimerval 3 ,
163.Xr timeradd 3
164.Sh STANDARDS
165The functions conform to
166.St -p1003.1-2001 .
167The later
168.St -p1003.1-2008
169revision however marked both as obsolescent,
170recommending the use of
171.Xr timer_gettime 2
172and
173.Xr timer_settime 2
174instead.
175.Sh HISTORY
176The
177.Fn getitimer
178function call appeared in
179.Bx 4.2 .
180