date and time created 89/07/02 15:22:51 by mckusick
[unix-history] / usr / src / lib / libc / sys / getitimer.2
CommitLineData
88b3ccf2
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
616f8a75 3.\"
88b3ccf2
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)getitimer.2 6.4 (Berkeley) %G%
616f8a75 17.\"
1d87bb13 18.TH GETITIMER 2 ""
616f8a75
KM
19.UC 5
20.SH NAME
21getitimer, setitimer \- get/set value of interval timer
22.SH SYNOPSIS
23.nf
24.ft B
25#include <sys/time.h>
26.PP
27.ft B
28#define ITIMER_REAL 0 /* real time intervals */
29#define ITIMER_VIRTUAL 1 /* virtual time intervals */
30#define ITIMER_PROF 2 /* user and system virtual time */
31.sp
32.ft B
33getitimer(which, value)
34int which;
35struct itimerval *value;
36.PP
37.ft B
38setitimer(which, value, ovalue)
39int which;
40struct itimerval *value, *ovalue;
41.fi
42.SH DESCRIPTION
43The system provides each process with three interval timers,
44defined in
45.RI < sys/time.h >.
46The
47.I getitimer
48call returns the current value for the timer specified in
1d87bb13
KM
49.I which
50in the structure at
51.IR value .
52The
616f8a75 53.I setitimer
1d87bb13
KM
54call sets a timer to the specified
55.I value
56(returning the previous value of the timer if
57.I ovalue
58is nonzero).
616f8a75
KM
59.PP
60A timer value is defined by the
61.I itimerval
62structure:
63.PP
64.nf
65.RS
66.DT
67struct itimerval {
68 struct timeval it_interval; /* timer interval */
69 struct timeval it_value; /* current value */
70};
71.RE
72.fi
73.PP
74If
75.I it_value
76is non-zero, it indicates the time to the next timer expiration.
77If
78.I it_interval
79is non-zero, it specifies a value to be used in reloading
80.I it_value
81when the timer expires.
82Setting
83.I it_value
84to 0 disables a timer. Setting
85.I it_interval
86to 0 causes a timer to be disabled after its next expiration (assuming
87.I it_value
88is non-zero).
89.PP
90Time values smaller than the resolution of the
91system clock are rounded up to this resolution
1d87bb13 92(on the VAX, 10 milliseconds).
616f8a75
KM
93.PP
94The ITIMER_REAL timer decrements in real time. A SIGALRM signal is
95delivered when this timer expires.
96.PP
97The ITIMER_VIRTUAL timer decrements in process virtual time.
98It runs only when the process is executing. A SIGVTALRM signal
99is delivered when it expires.
100.PP
101The ITIMER_PROF timer decrements both in process virtual time and
102when the system is running on behalf of the process. It is designed
103to be used by interpreters in statistically profiling the execution
104of interpreted programs.
105Each time the ITIMER_PROF timer expires, the SIGPROF signal is
106delivered. Because this signal may interrupt in-progress
107system calls, programs using this timer must be prepared to
108restart interrupted system calls.
109.SH NOTES
110Three macros for manipulating time values are defined in
111.RI < sys/time.h >.
112.I Timerclear
113sets a time value to zero,
114.I timerisset
115tests if a time value is non-zero, and
116.I timercmp
117compares two time values (beware that >= and <= do not
118work with this macro).
119.SH "RETURN VALUE
120If the calls succeed, a value of 0 is returned. If an error occurs,
121the value \-1 is returned, and a more precise error code is placed
122in the global variable \fIerrno\fP.
123.SH "ERRORS
124The possible errors are:
125.TP 15
126[EFAULT]
fd690c8b 127The \fIvalue\fP parameter specified a bad address.
616f8a75
KM
128.TP 15
129[EINVAL]
fd690c8b 130A \fIvalue\fP parameter specified a time was too large
616f8a75
KM
131to be handled.
132.SH "SEE ALSO"
d0528fe6 133select(2), sigvec(2), gettimeofday(2)