1*47208Scael.\" Copyright (c) 1983, 1991 The Regents of the University of California. 238053Sbostic.\" All rights reserved. 320229Smckusick.\" 443568Strent.\" %sccs.include.redist.man% 520229Smckusick.\" 6*47208Scael.\" @(#)getitimer.2 6.6 (Berkeley) 03/10/91 738053Sbostic.\" 8*47208Scael.Dd 9*47208Scael.Dt GETITIMER 2 10*47208Scael.Os BSD 4.2 11*47208Scael.Sh NAME 12*47208Scael.Nm getitimer , 13*47208Scael.Nm setitimer 14*47208Scael.Nd get/set value of interval timer 15*47208Scael.Sh SYNOPSIS 16*47208Scael.Fd #include <sys/time.h> 17*47208Scael.Fd #define ITIMER_REAL 0 18*47208Scael.Fd #define ITIMER_VIRTUAL 1 19*47208Scael.Fd #define ITIMER_PROF 2 20*47208Scael.Ft int 21*47208Scael.Fn getitimer "int which" "struct itimerval *value" 22*47208Scael.Ft int 23*47208Scael.Fn setitimer "int which" "struct itimerval *value" "struct itimerval *ovalue" 24*47208Scael.Sh DESCRIPTION 2520229SmckusickThe system provides each process with three interval timers, 2620229Smckusickdefined in 27*47208Scael.Ao Pa sys/time.h Ac . 2820229SmckusickThe 29*47208Scael.Fn getitimer 3020229Smckusickcall returns the current value for the timer specified in 31*47208Scael.Fa which 3220230Smckusickin the structure at 33*47208Scael.Fa value . 3420230SmckusickThe 35*47208Scael.Fn setitimer 3620230Smckusickcall sets a timer to the specified 37*47208Scael.Fa value 3820230Smckusick(returning the previous value of the timer if 39*47208Scael.Fa ovalue 40*47208Scaelis non-nil). 41*47208Scael.Pp 4220229SmckusickA timer value is defined by the 43*47208Scael.Fa itimerval 4420229Smckusickstructure: 45*47208Scael.Bd -literal -offset indent 4620229Smckusickstruct itimerval { 4720229Smckusick struct timeval it_interval; /* timer interval */ 4820229Smckusick struct timeval it_value; /* current value */ 4920229Smckusick}; 50*47208Scael.Ed 51*47208Scael.Pp 5220229SmckusickIf 53*47208Scael.Fa it_value 5420229Smckusickis non-zero, it indicates the time to the next timer expiration. 5520229SmckusickIf 56*47208Scael.Fa it_interval 5720229Smckusickis non-zero, it specifies a value to be used in reloading 58*47208Scael.Fa it_value 5920229Smckusickwhen the timer expires. 6020229SmckusickSetting 61*47208Scael.Fa it_value 6220229Smckusickto 0 disables a timer. Setting 63*47208Scael.Fa it_interval 6420229Smckusickto 0 causes a timer to be disabled after its next expiration (assuming 65*47208Scael.Fa it_value 6620229Smckusickis non-zero). 67*47208Scael.Pp 6820229SmckusickTime values smaller than the resolution of the 6920229Smckusicksystem clock are rounded up to this resolution 70*47208Scael(typically 10 milliseconds). 71*47208Scael.Pp 72*47208ScaelThe 73*47208Scael.Dv ITIMER_REAL 74*47208Scaeltimer decrements in real time. A 75*47208Scael.Dv SIGALRM 76*47208Scaelsignal is 7720229Smckusickdelivered when this timer expires. 78*47208Scael.Pp 79*47208ScaelThe 80*47208Scael.Dv ITIMER_VIRTUAL 81*47208Scaeltimer decrements in process virtual time. 82*47208ScaelIt runs only when the process is executing. A 83*47208Scael.Dv SIGVTALRM 84*47208Scaelsignal 8520229Smckusickis delivered when it expires. 86*47208Scael.Pp 87*47208ScaelThe 88*47208Scael.Dv ITIMER_PROF 89*47208Scaeltimer decrements both in process virtual time and 9020229Smckusickwhen the system is running on behalf of the process. It is designed 9120229Smckusickto be used by interpreters in statistically profiling the execution 9220229Smckusickof interpreted programs. 93*47208ScaelEach time the 94*47208Scael.Dv ITIMER_PROF 95*47208Scaeltimer expires, the 96*47208Scael.Dv SIGPROF 97*47208Scaelsignal is 9820229Smckusickdelivered. Because this signal may interrupt in-progress 9920229Smckusicksystem calls, programs using this timer must be prepared to 10020229Smckusickrestart interrupted system calls. 101*47208Scael.Sh NOTES 10220229SmckusickThree macros for manipulating time values are defined in 103*47208Scael.Ao Pa sys/time.h Ac . 104*47208Scael.Fa Timerclear 10520229Smckusicksets a time value to zero, 106*47208Scael.Fa timerisset 10720229Smckusicktests if a time value is non-zero, and 108*47208Scael.Fa timercmp 10920229Smckusickcompares two time values (beware that >= and <= do not 11020229Smckusickwork with this macro). 111*47208Scael.Sh RETURN VALUES 11220229SmckusickIf the calls succeed, a value of 0 is returned. If an error occurs, 113*47208Scaelthe value -1 is returned, and a more precise error code is placed 114*47208Scaelin the global variable 115*47208Scael.Va errno . 116*47208Scael.Sh ERRORS 117*47208Scael.Fn Getitimer 118*47208Scaeland 119*47208Scael.Fn setitimer 120*47208Scaelwill fail if: 121*47208Scael.Bl -tag -width Er 122*47208Scael.It Bq Er EFAULT 123*47208ScaelThe 124*47208Scael.Fa value 125*47208Scaelparameter specified a bad address. 126*47208Scael.It Bq Er EINVAL 127*47208ScaelA 128*47208Scael.Fa value 129*47208Scaelparameter specified a time was too large 13020229Smckusickto be handled. 131*47208Scael.El 132*47208Scael.Sh SEE ALSO 133*47208Scael.Xr select 2 , 134*47208Scael.Xr sigvec 2 , 135*47208Scael.Xr gettimeofday 2 136*47208Scael.Sh HISTORY 137*47208ScaelThe 138*47208Scael.Nm 139*47208Scaelfunction call appeared in 140*47208Scael.Bx 4.2 . 141