1*f14fb602SLionel Sambuc.\" $NetBSD: getitimer.2,v 1.28 2011/10/27 16:10:37 christos Exp $ 22fe8fb19SBen Gras.\" 32fe8fb19SBen Gras.\" Copyright (c) 1983, 1991, 1993 42fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 52fe8fb19SBen Gras.\" 62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 82fe8fb19SBen Gras.\" are met: 92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 102fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 122fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 132fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 142fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 152fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 162fe8fb19SBen Gras.\" without specific prior written permission. 172fe8fb19SBen Gras.\" 182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 192fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 222fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 242fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 252fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 262fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 272fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 282fe8fb19SBen Gras.\" SUCH DAMAGE. 292fe8fb19SBen Gras.\" 302fe8fb19SBen Gras.\" @(#)getitimer.2 8.3 (Berkeley) 5/16/95 312fe8fb19SBen Gras.\" 32*f14fb602SLionel Sambuc.Dd October 27, 2011 332fe8fb19SBen Gras.Dt GETITIMER 2 342fe8fb19SBen Gras.Os 352fe8fb19SBen Gras.Sh NAME 362fe8fb19SBen Gras.Nm getitimer , 372fe8fb19SBen Gras.Nm setitimer 382fe8fb19SBen Gras.Nd get/set value of interval timer 392fe8fb19SBen Gras.Sh LIBRARY 402fe8fb19SBen Gras.Lb libc 412fe8fb19SBen Gras.Sh SYNOPSIS 422fe8fb19SBen Gras.In sys/time.h 432fe8fb19SBen Gras.Ft int 442fe8fb19SBen Gras.Fn getitimer "int which" "struct itimerval *value" 452fe8fb19SBen Gras.Ft int 462fe8fb19SBen Gras.Fn setitimer "int which" "const struct itimerval * restrict value" "struct itimerval * restrict ovalue" 472fe8fb19SBen Gras.Sh DESCRIPTION 482fe8fb19SBen GrasThe system provides each process with three interval timers, 492fe8fb19SBen Grasdefined in 502fe8fb19SBen Gras.Ao Pa sys/time.h Ac . 512fe8fb19SBen GrasThe 522fe8fb19SBen Gras.Fn getitimer 532fe8fb19SBen Grascall returns the current value for the timer specified in 542fe8fb19SBen Gras.Fa which 552fe8fb19SBen Grasin the structure at 562fe8fb19SBen Gras.Fa value . 572fe8fb19SBen GrasThe 582fe8fb19SBen Gras.Fn setitimer 592fe8fb19SBen Grascall sets a timer to the specified 60*f14fb602SLionel Sambuc.Fa value , 61*f14fb602SLionel Sambucreturning the previous value of the timer if 622fe8fb19SBen Gras.Fa ovalue 63*f14fb602SLionel Sambucis not 64*f14fb602SLionel Sambuc.Dv NULL . 652fe8fb19SBen Gras.Pp 662fe8fb19SBen GrasA timer value is defined by the 672fe8fb19SBen Gras.Fa itimerval 682fe8fb19SBen Grasstructure: 692fe8fb19SBen Gras.Bd -literal -offset indent 702fe8fb19SBen Grasstruct itimerval { 712fe8fb19SBen Gras struct timeval it_interval; /* timer interval */ 722fe8fb19SBen Gras struct timeval it_value; /* current value */ 732fe8fb19SBen Gras}; 742fe8fb19SBen Gras.Ed 752fe8fb19SBen Gras.Pp 762fe8fb19SBen GrasIf 772fe8fb19SBen Gras.Fa it_value 782fe8fb19SBen Grasis non-zero, it indicates the time to the next timer expiration. 792fe8fb19SBen GrasIf 802fe8fb19SBen Gras.Fa it_interval 812fe8fb19SBen Grasis non-zero, it specifies a value to be used in reloading 822fe8fb19SBen Gras.Fa it_value 832fe8fb19SBen Graswhen the timer expires. 842fe8fb19SBen GrasSetting 852fe8fb19SBen Gras.Fa it_value 862fe8fb19SBen Grasto 0 disables a timer. 872fe8fb19SBen GrasSetting 882fe8fb19SBen Gras.Fa it_interval 892fe8fb19SBen Grasto 0 causes a timer to be disabled after its next expiration (assuming 902fe8fb19SBen Gras.Fa it_value 912fe8fb19SBen Grasis non-zero). 922fe8fb19SBen Gras.Pp 932fe8fb19SBen GrasThe 94*f14fb602SLionel Sambuc.Fa which 95*f14fb602SLionel Sambucparameter specifies the type of the timer: 96*f14fb602SLionel Sambuc.Bl -tag -width "ITIMER_MONOTONIC " -offset indent 97*f14fb602SLionel Sambuc.It Dv ITIMER_REAL 982fe8fb19SBen Grastimer decrements in real time. 99*f14fb602SLionel SambucThis timer is affected by 100*f14fb602SLionel Sambuc.Xr adjtime 2 101*f14fb602SLionel Sambucand 102*f14fb602SLionel Sambuc.Xr settimeofday 2 . 1032fe8fb19SBen GrasA 1042fe8fb19SBen Gras.Dv SIGALRM 1052fe8fb19SBen Grassignal is 1062fe8fb19SBen Grasdelivered when this timer expires. 107*f14fb602SLionel Sambuc.It Dv ITIMER_VIRTUAL 1082fe8fb19SBen Grastimer decrements in process virtual time. 1092fe8fb19SBen GrasIt runs only when the process is executing. 1102fe8fb19SBen GrasA 1112fe8fb19SBen Gras.Dv SIGVTALRM 1122fe8fb19SBen Grassignal 1132fe8fb19SBen Grasis delivered when it expires. 114*f14fb602SLionel Sambuc.It Dv ITIMER_PROF 1152fe8fb19SBen Grastimer decrements both in process virtual time and 1162fe8fb19SBen Graswhen the system is running on behalf of the process. 1172fe8fb19SBen GrasIt is designed to be used by interpreters in statistically profiling 1182fe8fb19SBen Grasthe execution of interpreted programs. 1192fe8fb19SBen GrasEach time the 1202fe8fb19SBen Gras.Dv ITIMER_PROF 1212fe8fb19SBen Grastimer expires, the 1222fe8fb19SBen Gras.Dv SIGPROF 1232fe8fb19SBen Grassignal is 1242fe8fb19SBen Grasdelivered. 1252fe8fb19SBen GrasBecause this signal may interrupt in-progress 1262fe8fb19SBen Grassystem calls, programs using this timer must be prepared to 1272fe8fb19SBen Grasrestart interrupted system calls. 128*f14fb602SLionel Sambuc.It Dv ITIMER_MONOTONIC 129*f14fb602SLionel Sambuctimer decrements in monotonic time. 130*f14fb602SLionel SambucThis timer is not affected by 131*f14fb602SLionel Sambuc.Xr adjtime 2 132*f14fb602SLionel Sambucand 133*f14fb602SLionel Sambuc.Xr settimeofday 2 . 134*f14fb602SLionel SambucA 135*f14fb602SLionel Sambuc.Dv SIGALRM 136*f14fb602SLionel Sambucsignal is 137*f14fb602SLionel Sambucdelivered when this timer expires. 138*f14fb602SLionel Sambuc.El 139*f14fb602SLionel SambucNote that: 140*f14fb602SLionel Sambuc.Bl -bullet -offset indent 141*f14fb602SLionel Sambuc.It 142*f14fb602SLionel SambucTime values smaller than the resolution of the 143*f14fb602SLionel Sambucsystem clock are rounded up to this resolution 144*f14fb602SLionel Sambuc(typically 10 milliseconds). 145*f14fb602SLionel Sambuc.It 146*f14fb602SLionel SambucThe interaction between 147*f14fb602SLionel Sambuc.Fn setitimer 148*f14fb602SLionel Sambucand 149*f14fb602SLionel Sambuc.Xr alarm 3 150*f14fb602SLionel Sambucor 151*f14fb602SLionel Sambuc.Xr sleep 3 152*f14fb602SLionel Sambucis unspecified by the specification. 153*f14fb602SLionel Sambuc.El 1542fe8fb19SBen Gras.Sh RETURN VALUES 1552fe8fb19SBen GrasIf the calls succeed, a value of 0 is returned. 1562fe8fb19SBen GrasIf an error occurs, the value \-1 is returned, and a more precise error 1572fe8fb19SBen Grascode is placed in the global variable 1582fe8fb19SBen Gras.Va errno . 1592fe8fb19SBen Gras.Sh ERRORS 160*f14fb602SLionel SambucBoth functions may fail if: 1612fe8fb19SBen Gras.Bl -tag -width Er 1622fe8fb19SBen Gras.It Bq Er EFAULT 1632fe8fb19SBen GrasThe 1642fe8fb19SBen Gras.Fa value 1652fe8fb19SBen Grasparameter specified a bad address. 1662fe8fb19SBen Gras.It Bq Er EINVAL 167*f14fb602SLionel SambucThe 168*f14fb602SLionel Sambuc.Fa which 169*f14fb602SLionel Sambucparameter was not a known timer type, or the 1702fe8fb19SBen Gras.Fa value 1712fe8fb19SBen Grasparameter specified a time that was too large 1722fe8fb19SBen Grasto be handled. 1732fe8fb19SBen Gras.El 1742fe8fb19SBen Gras.Sh SEE ALSO 1752fe8fb19SBen Gras.Xr gettimeofday 2 , 1762fe8fb19SBen Gras.Xr select 2 , 177*f14fb602SLionel Sambuc.Xr sigaction 2 , 178*f14fb602SLionel Sambuc.Xr itimerval 3 , 179*f14fb602SLionel Sambuc.Xr timeradd 3 1802fe8fb19SBen Gras.Sh STANDARDS 181*f14fb602SLionel SambucThe functions conform to 1822fe8fb19SBen Gras.St -p1003.1-2001 . 1832fe8fb19SBen GrasThe later 1842fe8fb19SBen Gras.St -p1003.1-2008 185*f14fb602SLionel Sambucrevision however marked both as obsolescent, 1862fe8fb19SBen Grasrecommending the use of 1872fe8fb19SBen Gras.Xr timer_gettime 2 1882fe8fb19SBen Grasand 1892fe8fb19SBen Gras.Xr timer_settime 2 1902fe8fb19SBen Grasinstead. 1912fe8fb19SBen Gras.Sh HISTORY 1922fe8fb19SBen GrasThe 1932fe8fb19SBen Gras.Fn getitimer 1942fe8fb19SBen Grasfunction call appeared in 1952fe8fb19SBen Gras.Bx 4.2 . 196*f14fb602SLionel SambucThe 197*f14fb602SLionel Sambuc.Dv ITIMER_MONOTONIC 198*f14fb602SLionel Sambucfunctionality appeared in 199*f14fb602SLionel Sambuc.Nx 6.0 . 200