408 lines
9.8 KiB
HTML
408 lines
9.8 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETITIMER</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETITIMER</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
getitimer, setitimer - get or set value of an interval timer
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/time.h">sys/time.h</A>></B>
|
|
|
|
<B>int getitimer(int </B><I>which</I><B>, struct itimerval *</B><I>curr_value</I><B>);</B>
|
|
<B>int setitimer(int </B><I>which</I><B>, const struct itimerval *</B><I>new_value</I><B>,</B>
|
|
<B> struct itimerval *</B><I>old_value</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
These system calls provide access to interval timers, that is,
|
|
timers that initially expire at some point in the future,
|
|
and (optionally) at regular intervals after that.
|
|
When a timer expires, a signal is generated for the calling process,
|
|
and the timer is reset to the specified interval
|
|
(if the interval is nonzero).
|
|
<P>
|
|
|
|
Three types of timers---specified via the
|
|
<I>which</I>
|
|
|
|
argument---are provided,
|
|
each of which counts against a different clock and
|
|
generates a different signal on timer expiration:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ITIMER_REAL</B>
|
|
|
|
<DD>
|
|
This timer counts down in real (i.e., wall clock) time.
|
|
At each expiration, a
|
|
<B>SIGALRM</B>
|
|
|
|
signal is generated.
|
|
<DT id="2"><B>ITIMER_VIRTUAL</B>
|
|
|
|
<DD>
|
|
This timer counts down against the user-mode CPU time consumed by the process.
|
|
(The measurement includes CPU time consumed by all threads in the process.)
|
|
At each expiration, a
|
|
<B>SIGVTALRM</B>
|
|
|
|
signal is generated.
|
|
<DT id="3"><B>ITIMER_PROF</B>
|
|
|
|
<DD>
|
|
This timer counts down against the total (i.e., both user and system)
|
|
CPU time consumed by the process.
|
|
(The measurement includes CPU time consumed by all threads in the process.)
|
|
At each expiration, a
|
|
<B>SIGPROF</B>
|
|
|
|
signal is generated.
|
|
<DT id="4"><DD>
|
|
In conjunction with
|
|
<B>ITIMER_VIRTUAL</B>,
|
|
|
|
this timer can be used to profile user and system CPU time
|
|
consumed by the process.
|
|
</DL>
|
|
<P>
|
|
|
|
A process has only one of each of the three types of timers.
|
|
<P>
|
|
|
|
Timer values are defined by the following structures:
|
|
<P>
|
|
|
|
|
|
|
|
struct itimerval {
|
|
<BR> struct timeval it_interval; /* Interval for periodic timer */
|
|
<BR> struct timeval it_value; /* Time until next expiration */
|
|
};
|
|
<P>
|
|
struct timeval {
|
|
<BR> time_t tv_sec; /* seconds */
|
|
<BR> suseconds_t tv_usec; /* microseconds */
|
|
};
|
|
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>getitimer()</H3>
|
|
|
|
The function
|
|
<B>getitimer</B>()
|
|
|
|
places the current value of the timer specified by
|
|
<I>which</I>
|
|
|
|
in the buffer pointed to by
|
|
<I>curr_value</I>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>it_value</I>
|
|
|
|
substructure is populated with the amount of time remaining until
|
|
the next expiration of the specified timer.
|
|
This value changes as the timer counts down, and will be reset to
|
|
<I>it_interval</I>
|
|
|
|
when the timer expires.
|
|
If both fields of
|
|
<I>it_value</I>
|
|
|
|
are zero, then this timer is currently disarmed (inactive).
|
|
<P>
|
|
|
|
The
|
|
<I>it_interval</I>
|
|
|
|
substructure is populated with the timer interval.
|
|
If both fields of
|
|
<I>it_interval</I>
|
|
|
|
are zero, then this is a single-shot timer (i.e., it expires just once).
|
|
<A NAME="lbAF"> </A>
|
|
<H3>setitimer()</H3>
|
|
|
|
The function
|
|
<B>setitimer</B>()
|
|
|
|
arms or disarms the timer specified by
|
|
<I>which</I>,
|
|
|
|
by setting the timer to the value specified by
|
|
<I>new_value</I>.
|
|
|
|
If
|
|
<I>old_value</I>
|
|
|
|
is non-NULL,
|
|
the buffer it points to is used to return the previous value of the timer
|
|
(i.e., the same information that is returned by
|
|
<B>getitimer</B>()).
|
|
|
|
<P>
|
|
|
|
If either field in
|
|
<I>new_value.it_value</I>
|
|
|
|
is nonzero,
|
|
then the timer is armed to initially expire at the specified time.
|
|
If both fields in
|
|
<I>new_value.it_value</I>
|
|
|
|
are zero, then the timer is disarmed.
|
|
<P>
|
|
|
|
The
|
|
<I>new_value.it_interval</I>
|
|
|
|
field specifies the new interval for the timer;
|
|
if both of its subfields are zero, the timer is single-shot.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, zero is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="5"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
<I>new_value</I>,
|
|
|
|
<I>old_value</I>,
|
|
|
|
or
|
|
<I>curr_value</I>
|
|
|
|
is not valid a pointer.
|
|
<DT id="6"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>which</I>
|
|
|
|
is not one of
|
|
<B>ITIMER_REAL</B>,
|
|
|
|
<B>ITIMER_VIRTUAL</B>,
|
|
|
|
or
|
|
<B>ITIMER_PROF</B>;
|
|
|
|
or (since Linux 2.6.22) one of the
|
|
<I>tv_usec</I>
|
|
|
|
fields in the structure pointed to by
|
|
<I>new_value</I>
|
|
|
|
contains a value outside the range 0 to 999999.
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, SVr4, 4.4BSD (this call first appeared in 4.2BSD).
|
|
POSIX.1-2008 marks
|
|
<B>getitimer</B>()
|
|
|
|
and
|
|
<B>setitimer</B>()
|
|
|
|
obsolete, recommending the use of the POSIX timers API
|
|
(<B><A HREF="/cgi-bin/man/man2html?2+timer_gettime">timer_gettime</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timer_settime">timer_settime</A></B>(2),
|
|
|
|
etc.) instead.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Timers will never expire before the requested time,
|
|
but may expire some (short) time afterward, which depends
|
|
on the system timer resolution and on the system load; see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7).
|
|
|
|
(But see BUGS below.)
|
|
If the timer expires while the process is active (always true for
|
|
<B>ITIMER_VIRTUAL</B>),
|
|
|
|
the signal will be delivered immediately when generated.
|
|
<P>
|
|
|
|
A child created via
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fork">fork</A></B>(2)
|
|
|
|
does not inherit its parent's interval timers.
|
|
Interval timers are preserved across an
|
|
<B><A HREF="/cgi-bin/man/man2html?2+execve">execve</A></B>(2).
|
|
|
|
<P>
|
|
|
|
POSIX.1 leaves the
|
|
interaction between
|
|
<B>setitimer</B>()
|
|
|
|
and the three interfaces
|
|
<B><A HREF="/cgi-bin/man/man2html?2+alarm">alarm</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sleep">sleep</A></B>(3),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+usleep">usleep</A></B>(3)
|
|
|
|
unspecified.
|
|
<P>
|
|
|
|
The standards are silent on the meaning of the call:
|
|
<P>
|
|
|
|
<BR> setitimer(which, NULL, &old_value);
|
|
<P>
|
|
|
|
Many systems (Solaris, the BSDs, and perhaps others)
|
|
treat this as equivalent to:
|
|
<P>
|
|
|
|
<BR> getitimer(which, &old_value);
|
|
<P>
|
|
|
|
In Linux, this is treated as being equivalent to a call in which the
|
|
<I>new_value</I>
|
|
|
|
fields are zero; that is, the timer is disabled.
|
|
<I>Don't use this Linux misfeature</I>:
|
|
|
|
it is nonportable and unnecessary.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
The generation and delivery of a signal are distinct, and
|
|
only one instance of each of the signals listed above may be pending
|
|
for a process.
|
|
Under very heavy loading, an
|
|
<B>ITIMER_REAL</B>
|
|
|
|
timer may expire before the signal from a previous expiration
|
|
has been delivered.
|
|
The second signal in such an event will be lost.
|
|
<P>
|
|
|
|
On Linux kernels before 2.6.16, timer values are represented in jiffies.
|
|
If a request is made set a timer with a value whose jiffies
|
|
representation exceeds
|
|
<B>MAX_SEC_IN_JIFFIES</B>
|
|
|
|
(defined in
|
|
<I>include/linux/jiffies.h</I>),
|
|
|
|
then the timer is silently truncated to this ceiling value.
|
|
On Linux/i386 (where, since Linux 2.6.13,
|
|
the default jiffy is 0.004 seconds),
|
|
this means that the ceiling value for a timer is
|
|
approximately 99.42 days.
|
|
Since Linux 2.6.16,
|
|
the kernel uses a different internal representation for times,
|
|
and this ceiling is removed.
|
|
<P>
|
|
|
|
On certain systems (including i386),
|
|
Linux kernels before version 2.6.12 have a bug which will produce
|
|
premature timer expirations of up to one jiffy under some circumstances.
|
|
This bug is fixed in kernel 2.6.12.
|
|
|
|
|
|
<P>
|
|
|
|
POSIX.1-2001 says that
|
|
<B>setitimer</B>()
|
|
|
|
should fail if a
|
|
<I>tv_usec</I>
|
|
|
|
value is specified that is outside of the range 0 to 999999.
|
|
However, in kernels up to and including 2.6.21,
|
|
Linux does not give an error, but instead silently
|
|
adjusts the corresponding seconds value for the timer.
|
|
From kernel 2.6.22 onward,
|
|
this nonconformance has been repaired:
|
|
an improper
|
|
<I>tv_usec</I>
|
|
|
|
value results in an
|
|
<B>EINVAL</B>
|
|
|
|
error.
|
|
|
|
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+gettimeofday">gettimeofday</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sigaction">sigaction</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+signal">signal</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timer_create">timer_create</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+timerfd_create">timerfd_create</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="7"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="8"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="9"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="10"><A HREF="#lbAE">getitimer()</A><DD>
|
|
<DT id="11"><A HREF="#lbAF">setitimer()</A><DD>
|
|
</DL>
|
|
<DT id="12"><A HREF="#lbAG">RETURN VALUE</A><DD>
|
|
<DT id="13"><A HREF="#lbAH">ERRORS</A><DD>
|
|
<DT id="14"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="15"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DT id="16"><A HREF="#lbAK">BUGS</A><DD>
|
|
<DT id="17"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="18"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:32 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|