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               long tv_sec;                /* seconds */
41               long 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  afterwards, 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

BUGS

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

SEE ALSO

125       gettimeofday(2), sigaction(2), signal(2), timer_create(2), timerfd_cre‐
126       ate(2), time(7)
127

COLOPHON

129       This  page  is  part of release 3.22 of the Linux man-pages project.  A
130       description of the project, and information about reporting  bugs,  can
131       be found at http://www.kernel.org/doc/man-pages/.
132
133
134
135Linux                             2009-03-15                      GETITIMER(2)
Impressum