xref: /netbsd-src/lib/libc/sys/getitimer.2 (revision 7b4757a1251614c9363259336da8181d35fc3a61)
1*7b4757a1Spgoyette.\"	$NetBSD: getitimer.2,v 1.29 2019/04/27 22:00:29 pgoyette Exp $
24eab61bdScgd.\"
34eab61bdScgd.\" Copyright (c) 1983, 1991, 1993
44eab61bdScgd.\"	The Regents of the University of California.  All rights reserved.
561f28255Scgd.\"
661f28255Scgd.\" Redistribution and use in source and binary forms, with or without
761f28255Scgd.\" modification, are permitted provided that the following conditions
861f28255Scgd.\" are met:
961f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1061f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1161f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1261f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1361f28255Scgd.\"    documentation and/or other materials provided with the distribution.
14eb7c1594Sagc.\" 3. Neither the name of the University nor the names of its contributors
1561f28255Scgd.\"    may be used to endorse or promote products derived from this software
1661f28255Scgd.\"    without specific prior written permission.
1761f28255Scgd.\"
1861f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1961f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2061f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2161f28255Scgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2261f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2361f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2461f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2561f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2661f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2761f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2861f28255Scgd.\" SUCH DAMAGE.
2961f28255Scgd.\"
30a5c24028Sperry.\"     @(#)getitimer.2	8.3 (Berkeley) 5/16/95
3161f28255Scgd.\"
32*7b4757a1Spgoyette.Dd April 28, 2019
3361f28255Scgd.Dt GETITIMER 2
3438c96853Sgarbled.Os
3561f28255Scgd.Sh NAME
3661f28255Scgd.Nm getitimer ,
3761f28255Scgd.Nm setitimer
3861f28255Scgd.Nd get/set value of interval timer
3915be242bSkleink.Sh LIBRARY
4015be242bSkleink.Lb libc
4161f28255Scgd.Sh SYNOPSIS
42472351e1Swiz.In sys/time.h
4361f28255Scgd.Ft int
4461f28255Scgd.Fn getitimer "int which" "struct itimerval *value"
4561f28255Scgd.Ft int
46681b62c2Skleink.Fn setitimer "int which" "const struct itimerval * restrict value" "struct itimerval * restrict ovalue"
4761f28255Scgd.Sh DESCRIPTION
48*7b4757a1SpgoyetteThe system provides each process with multiple interval timers,
4961f28255Scgddefined in
5061f28255Scgd.Ao Pa sys/time.h Ac .
5161f28255ScgdThe
5261f28255Scgd.Fn getitimer
5361f28255Scgdcall returns the current value for the timer specified in
5461f28255Scgd.Fa which
5561f28255Scgdin the structure at
5661f28255Scgd.Fa value .
5761f28255ScgdThe
5861f28255Scgd.Fn setitimer
5961f28255Scgdcall sets a timer to the specified
6004b57bd8Sjruoho.Fa value ,
6104b57bd8Sjruohoreturning the previous value of the timer if
6261f28255Scgd.Fa ovalue
6304b57bd8Sjruohois not
6404b57bd8Sjruoho.Dv NULL .
6561f28255Scgd.Pp
6661f28255ScgdA timer value is defined by the
6761f28255Scgd.Fa itimerval
6861f28255Scgdstructure:
6961f28255Scgd.Bd -literal -offset indent
7061f28255Scgdstruct itimerval {
7161f28255Scgd	struct	timeval it_interval;	/* timer interval */
7261f28255Scgd	struct	timeval it_value;	/* current value */
7361f28255Scgd};
7461f28255Scgd.Ed
7561f28255Scgd.Pp
7661f28255ScgdIf
7761f28255Scgd.Fa it_value
7861f28255Scgdis non-zero, it indicates the time to the next timer expiration.
7961f28255ScgdIf
8061f28255Scgd.Fa it_interval
8161f28255Scgdis non-zero, it specifies a value to be used in reloading
8261f28255Scgd.Fa it_value
8361f28255Scgdwhen the timer expires.
8461f28255ScgdSetting
8561f28255Scgd.Fa it_value
86f6bcf964Swizto 0 disables a timer.
87f6bcf964SwizSetting
8861f28255Scgd.Fa it_interval
8961f28255Scgdto 0 causes a timer to be disabled after its next expiration (assuming
9061f28255Scgd.Fa it_value
9161f28255Scgdis non-zero).
9261f28255Scgd.Pp
9361f28255ScgdThe
9404b57bd8Sjruoho.Fa which
9504b57bd8Sjruohoparameter specifies the type of the timer:
968f5455bfSchristos.Bl -tag -width "ITIMER_MONOTONIC " -offset indent
9704b57bd8Sjruoho.It Dv ITIMER_REAL
98f6bcf964Swiztimer decrements in real time.
998f5455bfSchristosThis timer is affected by
1008f5455bfSchristos.Xr adjtime 2
1018f5455bfSchristosand
1028f5455bfSchristos.Xr settimeofday 2 .
103f6bcf964SwizA
10461f28255Scgd.Dv SIGALRM
10561f28255Scgdsignal is
10661f28255Scgddelivered when this timer expires.
10704b57bd8Sjruoho.It Dv ITIMER_VIRTUAL
10861f28255Scgdtimer decrements in process virtual time.
109f6bcf964SwizIt runs only when the process is executing.
110f6bcf964SwizA
11161f28255Scgd.Dv SIGVTALRM
11261f28255Scgdsignal
11361f28255Scgdis delivered when it expires.
11404b57bd8Sjruoho.It Dv ITIMER_PROF
11561f28255Scgdtimer decrements both in process virtual time and
116f6bcf964Swizwhen the system is running on behalf of the process.
117f6bcf964SwizIt is designed to be used by interpreters in statistically profiling
118f6bcf964Swizthe execution of interpreted programs.
11961f28255ScgdEach time the
12061f28255Scgd.Dv ITIMER_PROF
12161f28255Scgdtimer expires, the
12261f28255Scgd.Dv SIGPROF
12361f28255Scgdsignal is
124f6bcf964Swizdelivered.
125f6bcf964SwizBecause this signal may interrupt in-progress
12661f28255Scgdsystem calls, programs using this timer must be prepared to
12761f28255Scgdrestart interrupted system calls.
1288f5455bfSchristos.It Dv ITIMER_MONOTONIC
1298f5455bfSchristostimer decrements in monotonic time.
1308f5455bfSchristosThis timer is not affected by
1318f5455bfSchristos.Xr adjtime 2
1328f5455bfSchristosand
1338f5455bfSchristos.Xr settimeofday 2 .
1348f5455bfSchristosA
1358f5455bfSchristos.Dv SIGALRM
1368f5455bfSchristossignal is
1378f5455bfSchristosdelivered when this timer expires.
138a192422bSjruoho.El
139a192422bSjruohoNote that:
140a192422bSjruoho.Bl -bullet -offset indent
141a192422bSjruoho.It
142a192422bSjruohoTime values smaller than the resolution of the
143a192422bSjruohosystem clock are rounded up to this resolution
144a192422bSjruoho(typically 10 milliseconds).
145a192422bSjruoho.It
146a192422bSjruohoThe interaction between
147a192422bSjruoho.Fn setitimer
148a192422bSjruohoand
149a192422bSjruoho.Xr alarm 3
150a192422bSjruohoor
151a192422bSjruoho.Xr sleep 3
152a192422bSjruohois unspecified by the specification.
153a192422bSjruoho.El
15461f28255Scgd.Sh RETURN VALUES
155f6bcf964SwizIf the calls succeed, a value of 0 is returned.
15664ebeb5cSwizIf an error occurs, the value \-1 is returned, and a more precise error
157f6bcf964Swizcode is placed in the global variable
15861f28255Scgd.Va errno .
15961f28255Scgd.Sh ERRORS
160a192422bSjruohoBoth functions may fail if:
16161f28255Scgd.Bl -tag -width Er
16261f28255Scgd.It Bq Er EFAULT
16361f28255ScgdThe
16461f28255Scgd.Fa value
16561f28255Scgdparameter specified a bad address.
16661f28255Scgd.It Bq Er EINVAL
167e2c203c8SnjolyThe
168e2c203c8Snjoly.Fa which
169e2c203c8Snjolyparameter was not a known timer type, or the
17061f28255Scgd.Fa value
1714eab61bdScgdparameter specified a time that was too large
17261f28255Scgdto be handled.
17361f28255Scgd.El
17461f28255Scgd.Sh SEE ALSO
17553d84b5cSwiz.Xr gettimeofday 2 ,
17661f28255Scgd.Xr select 2 ,
17704b57bd8Sjruoho.Xr sigaction 2 ,
17804b57bd8Sjruoho.Xr itimerval 3 ,
17904b57bd8Sjruoho.Xr timeradd 3
180eccc1c42Sjruoho.Sh STANDARDS
18104b57bd8SjruohoThe functions conform to
182eccc1c42Sjruoho.St -p1003.1-2001 .
183eccc1c42SjruohoThe later
184eccc1c42Sjruoho.St -p1003.1-2008
18504b57bd8Sjruohorevision however marked both as obsolescent,
186eccc1c42Sjruohorecommending the use of
187eccc1c42Sjruoho.Xr timer_gettime 2
188eccc1c42Sjruohoand
189eccc1c42Sjruoho.Xr timer_settime 2
190eccc1c42Sjruohoinstead.
19161f28255Scgd.Sh HISTORY
19261f28255ScgdThe
1936e9ac180Sjtc.Fn getitimer
19461f28255Scgdfunction call appeared in
19561f28255Scgd.Bx 4.2 .
1968f5455bfSchristosThe
1978f5455bfSchristos.Dv ITIMER_MONOTONIC
1988f5455bfSchristosfunctionality appeared in
1998f5455bfSchristos.Nx 6.0 .
200