161181Sbostic.\" Copyright (c) 1983, 1991, 1993 261181Sbostic.\" The Regents of the University of California. All rights reserved. 320229Smckusick.\" 443568Strent.\" %sccs.include.redist.man% 520229Smckusick.\" 6*69506Smckusick.\" @(#)getitimer.2 8.3 (Berkeley) 05/16/95 738053Sbostic.\" 847208Scael.Dd 947208Scael.Dt GETITIMER 2 1047208Scael.Os BSD 4.2 1147208Scael.Sh NAME 1247208Scael.Nm getitimer , 1347208Scael.Nm setitimer 1447208Scael.Nd get/set value of interval timer 1547208Scael.Sh SYNOPSIS 1647208Scael.Fd #include <sys/time.h> 1747208Scael.Fd #define ITIMER_REAL 0 1847208Scael.Fd #define ITIMER_VIRTUAL 1 1947208Scael.Fd #define ITIMER_PROF 2 2047208Scael.Ft int 2147208Scael.Fn getitimer "int which" "struct itimerval *value" 2247208Scael.Ft int 2347208Scael.Fn setitimer "int which" "struct itimerval *value" "struct itimerval *ovalue" 2447208Scael.Sh DESCRIPTION 2520229SmckusickThe system provides each process with three interval timers, 2620229Smckusickdefined in 2747208Scael.Ao Pa sys/time.h Ac . 2820229SmckusickThe 2947208Scael.Fn getitimer 3020229Smckusickcall returns the current value for the timer specified in 3147208Scael.Fa which 3220230Smckusickin the structure at 3347208Scael.Fa value . 3420230SmckusickThe 3547208Scael.Fn setitimer 3620230Smckusickcall sets a timer to the specified 3747208Scael.Fa value 3820230Smckusick(returning the previous value of the timer if 3947208Scael.Fa ovalue 4047208Scaelis non-nil). 4147208Scael.Pp 4220229SmckusickA timer value is defined by the 4347208Scael.Fa itimerval 4420229Smckusickstructure: 4547208Scael.Bd -literal -offset indent 4620229Smckusickstruct itimerval { 4720229Smckusick struct timeval it_interval; /* timer interval */ 4820229Smckusick struct timeval it_value; /* current value */ 4920229Smckusick}; 5047208Scael.Ed 5147208Scael.Pp 5220229SmckusickIf 5347208Scael.Fa it_value 5420229Smckusickis non-zero, it indicates the time to the next timer expiration. 5520229SmckusickIf 5647208Scael.Fa it_interval 5720229Smckusickis non-zero, it specifies a value to be used in reloading 5847208Scael.Fa it_value 5920229Smckusickwhen the timer expires. 6020229SmckusickSetting 6147208Scael.Fa it_value 6220229Smckusickto 0 disables a timer. Setting 6347208Scael.Fa it_interval 6420229Smckusickto 0 causes a timer to be disabled after its next expiration (assuming 6547208Scael.Fa it_value 6620229Smckusickis non-zero). 6747208Scael.Pp 6820229SmckusickTime values smaller than the resolution of the 6920229Smckusicksystem clock are rounded up to this resolution 7047208Scael(typically 10 milliseconds). 7147208Scael.Pp 7247208ScaelThe 7347208Scael.Dv ITIMER_REAL 7447208Scaeltimer decrements in real time. A 7547208Scael.Dv SIGALRM 7647208Scaelsignal is 7720229Smckusickdelivered when this timer expires. 7847208Scael.Pp 7947208ScaelThe 8047208Scael.Dv ITIMER_VIRTUAL 8147208Scaeltimer decrements in process virtual time. 8247208ScaelIt runs only when the process is executing. A 8347208Scael.Dv SIGVTALRM 8447208Scaelsignal 8520229Smckusickis delivered when it expires. 8647208Scael.Pp 8747208ScaelThe 8847208Scael.Dv ITIMER_PROF 8947208Scaeltimer 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. 9347208ScaelEach time the 9447208Scael.Dv ITIMER_PROF 9547208Scaeltimer expires, the 9647208Scael.Dv SIGPROF 9747208Scaelsignal is 9820229Smckusickdelivered. Because this signal may interrupt in-progress 9920229Smckusicksystem calls, programs using this timer must be prepared to 10020229Smckusickrestart interrupted system calls. 10147208Scael.Sh NOTES 10220229SmckusickThree macros for manipulating time values are defined in 10347208Scael.Ao Pa sys/time.h Ac . 10447208Scael.Fa Timerclear 10520229Smckusicksets a time value to zero, 10647208Scael.Fa timerisset 10720229Smckusicktests if a time value is non-zero, and 10847208Scael.Fa timercmp 109*69506Smckusickcompares two time values. 11047208Scael.Sh RETURN VALUES 11120229SmckusickIf the calls succeed, a value of 0 is returned. If an error occurs, 11247208Scaelthe value -1 is returned, and a more precise error code is placed 11347208Scaelin the global variable 11447208Scael.Va errno . 11547208Scael.Sh ERRORS 11647208Scael.Fn Getitimer 11747208Scaeland 11847208Scael.Fn setitimer 11947208Scaelwill fail if: 12047208Scael.Bl -tag -width Er 12147208Scael.It Bq Er EFAULT 12247208ScaelThe 12347208Scael.Fa value 12447208Scaelparameter specified a bad address. 12547208Scael.It Bq Er EINVAL 12647208ScaelA 12747208Scael.Fa value 12865100Smckusickparameter specified a time that was too large 12920229Smckusickto be handled. 13047208Scael.El 13147208Scael.Sh SEE ALSO 13247208Scael.Xr select 2 , 13347208Scael.Xr sigvec 2 , 13447208Scael.Xr gettimeofday 2 13547208Scael.Sh HISTORY 13647208ScaelThe 13747208Scael.Nm 13847208Scaelfunction call appeared in 13947208Scael.Bx 4.2 . 140