1TIME(7) Linux Programmer's Manual TIME(7)
2
3
4
6 time - overview of time and timers
7
9 Real time and process time
10 Real time is defined as time measured from some fixed point, either
11 from a standard point in the past (see the description of the Epoch and
12 calendar time below), or from some point (e.g., the start) in the life
13 of a process (elapsed time).
14
15 Process time is defined as the amount of CPU time used by a process.
16 This is sometimes divided into user and system components. User CPU
17 time is the time spent executing code in user mode. System CPU time is
18 the time spent by the kernel executing in system mode on behalf of the
19 process (e.g., executing system calls). The time(1) command can be
20 used to determine the amount of CPU time consumed during the execution
21 of a program. A program can determine the amount of CPU time it has
22 consumed using times(2), getrusage(2), or clock(3).
23
24 The Hardware Clock
25 Most computers have a (battery-powered) hardware clock which the kernel
26 reads at boot time in order to initialize the software clock. For fur‐
27 ther details, see rtc(4) and hwclock(8).
28
29 The Software Clock, HZ, and Jiffies
30 The accuracy of various system calls that set timeouts, (e.g.,
31 select(2), sigtimedwait(2)) and measure CPU time (e.g., getrusage(2))
32 is limited by the resolution of the software clock, a clock maintained
33 by the kernel which measures time in jiffies. The size of a jiffy is
34 determined by the value of the kernel constant HZ.
35
36 The value of HZ varies across kernel versions and hardware platforms.
37 On i386 the situation is as follows: on kernels up to and including
38 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with
39 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since
40 kernel 2.6.13, the HZ value is a kernel configuration parameter and can
41 be 100, 250 (the default) or 1000, yielding a jiffies value of, respec‐
42 tively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further
43 frequency is available: 300, a number that divides evenly for the com‐
44 mon video frame rates (PAL, 25 HZ; NTSC, 30 HZ).
45
46 The times(2) system call is a special case. It reports times with a
47 granularity defined by the kernel constant USER_HZ. Userspace applica‐
48 tions can determine the value of this constant using
49 sysconf(_SC_CLK_TCK).
50
51 High-Resolution Timers
52 Before Linux 2.6.21, the accuracy of timer and sleep system calls (see
53 below) was also limited by the size of the jiffy.
54
55 Since Linux 2.6.21, Linux supports high-resolution timers (HRTs),
56 optionally configurable via CONFIG_HIGH_RES_TIMERS. On a system that
57 supports HRTs, the accuracy of sleep and timer system calls is no
58 longer constrained by the jiffy, but instead can be as accurate as the
59 hardware allows (microsecond accuracy is typical of modern hardware).
60 You can determine whether high-resolution timers are supported by
61 checking the resolution returned by a call to clock_getres(2) or look‐
62 ing at the "resolution" entries in /proc/timer_list.
63
64 HRTs are not supported on all hardware architectures. (Support is pro‐
65 vided on x86, arm, and powerpc, among others.)
66
67 The Epoch
68 Unix systems represent time in seconds since the Epoch, which is
69 defined as 0:00:00 UTC on the morning of 1 January 1970.
70
71 A program can determine the calendar time using gettimeofday(2), which
72 returns time (in seconds and microseconds) that have elapsed since the
73 Epoch; time(2) provides similar information, but only with accuracy to
74 the nearest second. The system time can be changed using settimeof‐
75 day(2).
76
77 Broken-down time
78 Certain library functions use a structure of type tm to represent bro‐
79 ken-down time, which stores time value separated out into distinct com‐
80 ponents (year, month, day, hour, minute, second, etc.). This structure
81 is described in ctime(3), which also describes functions that convert
82 between calendar time and broken-down time. Functions for converting
83 between broken-down time and printable string representations of the
84 time are described in ctime(3), strftime(3), and strptime(3).
85
86 Sleeping and Setting Timers
87 Various system calls and functions allow a program to sleep (suspend
88 execution) for a specified period of time; see nanosleep(2),
89 clock_nanosleep(2), and sleep(3).
90
91 Various system calls allow a process to set a timer that expires at
92 some point in the future, and optionally at repeated intervals; see
93 alarm(2), getitimer(2), timerfd_create(2), and timer_create(2).
94
96 date(1), time(1), adjtimex(2), alarm(2), clock_gettime(2),
97 clock_nanosleep(2), getitimer(2), getrlimit(2), getrusage(2), gettime‐
98 ofday(2), nanosleep(2), stat(2), time(2), timer_create(2), timerfd_cre‐
99 ate(2), times(2), utime(2), adjtime(3), clock(3), clock_getcpu‐
100 clockid(3), ctime(3), pthread_getcpuclockid(3), sleep(3), strftime(3),
101 strptime(3), timeradd(3), usleep(3), rtc(4), hwclock(8)
102
104 This page is part of release 3.22 of the Linux man-pages project. A
105 description of the project, and information about reporting bugs, can
106 be found at http://www.kernel.org/doc/man-pages/.
107
108
109
110Linux 2009-02-10 TIME(7)