xref: /csrg-svn/lib/libc/sys/getitimer.2 (revision 65100)
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*65100Smckusick.\"     @(#)getitimer.2	8.2 (Berkeley) 12/11/93
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
10920229Smckusickcompares two time values (beware that >= and <= do not
11020229Smckusickwork with this macro).
11147208Scael.Sh RETURN VALUES
11220229SmckusickIf the calls succeed, a value of 0 is returned.  If an error occurs,
11347208Scaelthe value -1 is returned, and a more precise error code is placed
11447208Scaelin the global variable
11547208Scael.Va errno .
11647208Scael.Sh ERRORS
11747208Scael.Fn Getitimer
11847208Scaeland
11947208Scael.Fn setitimer
12047208Scaelwill fail if:
12147208Scael.Bl -tag -width Er
12247208Scael.It Bq Er EFAULT
12347208ScaelThe
12447208Scael.Fa value
12547208Scaelparameter specified a bad address.
12647208Scael.It Bq Er EINVAL
12747208ScaelA
12847208Scael.Fa value
129*65100Smckusickparameter specified a time that was too large
13020229Smckusickto be handled.
13147208Scael.El
13247208Scael.Sh SEE ALSO
13347208Scael.Xr select 2 ,
13447208Scael.Xr sigvec 2 ,
13547208Scael.Xr gettimeofday 2
13647208Scael.Sh HISTORY
13747208ScaelThe
13847208Scael.Nm
13947208Scaelfunction call appeared in
14047208Scael.Bx 4.2 .
141