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.\" $Id$ 34.\" 35.Dd May 16, 1995 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" "const 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, regardless of the value of 90.Fa it_interval . 91Setting 92.Fa it_interval 93to 0 causes a timer to be disabled after its next expiration (assuming 94.Fa it_value 95is non-zero). 96.Pp 97Time values smaller than the resolution of the 98system clock are rounded up to this resolution 99(typically 10 milliseconds). 100.Pp 101The 102.Dv ITIMER_REAL 103timer decrements in real time. A 104.Dv SIGALRM 105signal is 106delivered when this timer expires. 107.Pp 108The 109.Dv ITIMER_VIRTUAL 110timer decrements in process virtual time. 111It runs only when the process is executing. A 112.Dv SIGVTALRM 113signal 114is delivered when it expires. 115.Pp 116The 117.Dv ITIMER_PROF 118timer decrements both in process virtual time and 119when the system is running on behalf of the process. It is designed 120to be used by interpreters in statistically profiling the execution 121of interpreted programs. 122Each time the 123.Dv ITIMER_PROF 124timer expires, the 125.Dv SIGPROF 126signal is 127delivered. Because this signal may interrupt in-progress 128system calls, programs using this timer must be prepared to 129restart interrupted system calls. 130.Pp 131The maximum number of seconds allowed for 132.Fa it_interval 133and 134.Fa it_value 135in 136.Fn setitimer 137is 100000000. 138.Sh NOTES 139Three macros for manipulating time values are defined in 140.Ao Pa sys/time.h Ac . 141.Fa Timerclear 142sets a time value to zero, 143.Fa timerisset 144tests if a time value is non-zero, and 145.Fa timercmp 146compares two time values. 147.Sh RETURN VALUES 148If the calls succeed, a value of 0 is returned. If an error occurs, 149the value -1 is returned, and a more precise error code is placed 150in the global variable 151.Va errno . 152.Sh ERRORS 153.Fn Getitimer 154and 155.Fn setitimer 156will fail if: 157.Bl -tag -width Er 158.It Bq Er EFAULT 159The 160.Fa value 161parameter specified a bad address. 162.It Bq Er EINVAL 163A 164.Fa value 165parameter specified a time that was too large 166to be handled. 167.El 168.Sh SEE ALSO 169.Xr gettimeofday 2 , 170.Xr select 2 , 171.Xr sigvec 2 , 172.Xr clocks 7 173.Sh HISTORY 174The 175.Fn getitimer 176function call appeared in 177.Bx 4.2 . 178