1GETITIMER(2)               Linux Programmer's Manual              GETITIMER(2)
2
3
4

NAME

6       getitimer, setitimer - get or set value of an interval timer
7

SYNOPSIS

9       #include <sys/time.h>
10
11       int getitimer(int which, struct itimerval *curr_value);
12       int setitimer(int which, const struct itimerval *new_value,
13                     struct itimerval *old_value);
14

DESCRIPTION

16       The  system  provides  each  process  with  three interval timers, each
17       decrementing in a distinct time domain.  When any timer expires, a sig‐
18       nal is sent to the process, and the timer (potentially) restarts.
19
20       ITIMER_REAL    decrements in real time, and delivers SIGALRM upon expi‐
21                      ration.
22
23       ITIMER_VIRTUAL decrements only  when  the  process  is  executing,  and
24                      delivers SIGVTALRM upon expiration.
25
26       ITIMER_PROF    decrements  both  when the process executes and when the
27                      system is executing on behalf of the  process.   Coupled
28                      with  ITIMER_VIRTUAL, this timer is usually used to pro‐
29                      file the time spent by the application in user and  ker‐
30                      nel space.  SIGPROF is delivered upon expiration.
31
32       Timer values are defined by the following structures:
33
34           struct itimerval {
35               struct timeval it_interval; /* next value */
36               struct timeval it_value;    /* current value */
37           };
38
39           struct timeval {
40               time_t      tv_sec;         /* seconds */
41               suseconds_t tv_usec;        /* microseconds */
42           };
43
44       The  function  getitimer() fills the structure pointed to by curr_value
45       with the current setting for the  timer  specified  by  which  (one  of
46       ITIMER_REAL,  ITIMER_VIRTUAL, or ITIMER_PROF).  The element it_value is
47       set to the amount of time remaining on the timer, or zero if the  timer
48       is disabled.  Similarly, it_interval is set to the reset value.
49
50       The  function  setitimer()  sets  the  specified  timer to the value in
51       new_value.  If old_value is non-NULL, the old value  of  the  timer  is
52       stored there.
53
54       Timers decrement from it_value to zero, generate a signal, and reset to
55       it_interval.  A timer which is set to zero (it_value  is  zero  or  the
56       timer expires and it_interval is zero) stops.
57
58       Both  tv_sec and tv_usec are significant in determining the duration of
59       a timer.
60
61       Timers will never expire before the requested time, but may expire some
62       (short)  time  afterward,  which depends on the system timer resolution
63       and on the system load; see time(7).  (But see BUGS below.)  Upon expi‐
64       ration,  a  signal will be generated and the timer reset.  If the timer
65       expires while the process is active (always  true  for  ITIMER_VIRTUAL)
66       the signal will be delivered immediately when generated.  Otherwise the
67       delivery will be offset by a small time dependent on the  system  load‐
68       ing.
69

RETURN VALUE

71       On  success,  zero is returned.  On error, -1 is returned, and errno is
72       set appropriately.
73

ERRORS

75       EFAULT new_value, old_value, or curr_value is not valid a pointer.
76
77       EINVAL which is not one of ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF;
78              or  (since Linux 2.6.22) one of the tv_usec fields in the struc‐
79              ture pointed to by new_value contains a value outside the  range
80              0 to 999999.
81

CONFORMING TO

83       POSIX.1-2001,  SVr4,  4.4BSD  (this  call  first  appeared  in 4.2BSD).
84       POSIX.1-2008 marks getitimer() and setitimer()  obsolete,  recommending
85       the  use  of  the POSIX timers API (timer_gettime(2), timer_settime(2),
86       etc.) instead.
87

NOTES

89       A child created via fork(2) does  not  inherit  its  parent's  interval
90       timers.  Interval timers are preserved across an execve(2).
91
92       POSIX.1 leaves the interaction between setitimer() and the three inter‐
93       faces alarm(2), sleep(3), and usleep(3) unspecified.
94
95       The standards are silent on the meaning of the call:
96
97           setitimer(which, NULL, &old_value);
98
99       Many systems (Solaris, the BSDs, and  perhaps  others)  treat  this  as
100       equivalent to:
101
102           getitimer(which, &old_value);
103
104       In  Linux,  this  is treated as being equivalent to a call in which the
105       new_value fields are zero; that is, the timer is disabled.   Don't  use
106       this Linux misfeature: it is nonportable and unnecessary.
107

BUGS

109       The  generation  and  delivery  of  a signal are distinct, and only one
110       instance of each of the signals listed  above  may  be  pending  for  a
111       process.   Under  very  heavy  loading, an ITIMER_REAL timer may expire
112       before the signal from a previous expiration has been  delivered.   The
113       second signal in such an event will be lost.
114
115       On  Linux  kernels  before  2.6.16,  timer  values  are  represented in
116       jiffies.  If a request is made set a timer with a value  whose  jiffies
117       representation      exceeds      MAX_SEC_IN_JIFFIES     (defined     in
118       include/linux/jiffies.h), then the timer is silently truncated to  this
119       ceiling  value.   On Linux/i386 (where, since Linux 2.6.13, the default
120       jiffy is 0.004 seconds), this means that the ceiling value for a  timer
121       is  approximately  99.42  days.   Since Linux 2.6.16, the kernel uses a
122       different internal  representation  for  times,  and  this  ceiling  is
123       removed.
124
125       On  certain  systems  (including  i386),  Linux  kernels before version
126       2.6.12 have a bug which will produce premature timer expirations of  up
127       to  one  jiffy  under  some circumstances.  This bug is fixed in kernel
128       2.6.12.
129
130       POSIX.1-2001 says that setitimer() should fail if a  tv_usec  value  is
131       specified  that  is outside of the range 0 to 999999.  However, in ker‐
132       nels up to and including 2.6.21, Linux does  not  give  an  error,  but
133       instead silently adjusts the corresponding seconds value for the timer.
134       From kernel 2.6.22 onward, this nonconformance has  been  repaired:  an
135       improper tv_usec value results in an EINVAL error.
136

SEE ALSO

138       gettimeofday(2), sigaction(2), signal(2), timer_create(2), timerfd_cre‐
139       ate(2), time(7)
140

COLOPHON

142       This page is part of release 3.53 of the Linux  man-pages  project.   A
143       description  of  the project, and information about reporting bugs, can
144       be found at http://www.kernel.org/doc/man-pages/.
145
146
147
148Linux                             2012-10-01                      GETITIMER(2)
Impressum