1.\" $NetBSD: getitimer.2,v 1.24 2010/04/30 04:17:45 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 April 30, 2010 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.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 * restrict value" "struct itimerval * restrict ovalue" 50.Sh DESCRIPTION 51The system provides each process with three interval timers, 52defined in 53.Ao Pa sys/time.h Ac . 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-nil). 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 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. 120It is designed to be used by interpreters in statistically profiling 121the execution of interpreted programs. 122Each time the 123.Dv ITIMER_PROF 124timer expires, the 125.Dv SIGPROF 126signal is 127delivered. 128Because this signal may interrupt in-progress 129system calls, programs using this timer must be prepared to 130restart interrupted system calls. 131.Sh NOTES 132Macros for manipulating time values are defined in the 133.In sys/time.h 134header; 135.Fn timerclear 136sets a time value to zero, 137.Fn timerisset 138tests if a time value is non-zero, 139.Fn timercmp 140compares two time values, 141.Fn timeradd 142adds a time value to another time value, 143.Fn timersub 144computes the time difference between two time values. 145For additional details, see 146.Xr timeradd 3 . 147.Sh RETURN VALUES 148If the calls succeed, a value of 0 is returned. 149If an error occurs, the value \-1 is returned, and a more precise error 150code is placed in 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 poll 2 , 171.Xr select 2 , 172.Xr sigaction 2 173.Sh STANDARDS 174The 175.Fn getitimer 176and 177.Fn setitimer 178functions conform to 179.St -p1003.1-2001 . 180The later 181.St -p1003.1-2008 182revision however marked both functions as obsolescent, 183recommending the use of 184.Xr timer_gettime 2 185and 186.Xr timer_settime 2 187instead. 188.Sh HISTORY 189The 190.Fn getitimer 191function call appeared in 192.Bx 4.2 . 193