1time(7) Miscellaneous Information 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., se‐
31 lect(2), sigtimedwait(2)) and measure CPU time (e.g., getrusage(2)) is
32 limited by the resolution of the software clock, a clock maintained by
33 the kernel which measures time in jiffies. The size of a jiffy is de‐
34 termined 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 Linux 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting
39 with Linux 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 sec‐
40 onds. Since Linux 2.6.13, the HZ value is a kernel configuration pa‐
41 rameter and can be 100, 250 (the default) or 1000, yielding a jiffies
42 value of, respectively, 0.01, 0.004, or 0.001 seconds. Since Linux
43 2.6.20, a further frequency is available: 300, a number that divides
44 evenly for the common 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. User-space appli‐
48 cations can determine the value of this constant using
49 sysconf(_SC_CLK_TCK).
50
51 System and process clocks; time namespaces
52 The kernel supports a range of clocks that measure various kinds of
53 elapsed and virtual (i.e., consumed CPU) time. These clocks are de‐
54 scribed in clock_gettime(2). A few of the clocks are settable using
55 clock_settime(2). The values of certain clocks are virtualized by time
56 namespaces; see time_namespaces(7).
57
58 High-resolution timers
59 Before Linux 2.6.21, the accuracy of timer and sleep system calls (see
60 below) was also limited by the size of the jiffy.
61
62 Since Linux 2.6.21, Linux supports high-resolution timers (HRTs), op‐
63 tionally configurable via CONFIG_HIGH_RES_TIMERS. On a system that
64 supports HRTs, the accuracy of sleep and timer system calls is no
65 longer constrained by the jiffy, but instead can be as accurate as the
66 hardware allows (microsecond accuracy is typical of modern hardware).
67 You can determine whether high-resolution timers are supported by
68 checking the resolution returned by a call to clock_getres(2) or look‐
69 ing at the "resolution" entries in /proc/timer_list.
70
71 HRTs are not supported on all hardware architectures. (Support is pro‐
72 vided on x86, ARM, and PowerPC, among others.)
73
74 The Epoch
75 UNIX systems represent time in seconds since the Epoch, 1970-01-01
76 00:00:00 +0000 (UTC).
77
78 A program can determine the calendar time via the clock_gettime(2)
79 CLOCK_REALTIME clock, which returns time (in seconds and nanoseconds)
80 that have elapsed since the Epoch; time(2) provides similar informa‐
81 tion, but only with accuracy to the nearest second. The system time
82 can be changed using clock_settime(2).
83
84 Broken-down time
85 Certain library functions use a structure of type tm to represent bro‐
86 ken-down time, which stores time value separated out into distinct com‐
87 ponents (year, month, day, hour, minute, second, etc.). This structure
88 is described in tm(3type), which also describes functions that convert
89 between calendar time and broken-down time. Functions for converting
90 between broken-down time and printable string representations of the
91 time are described in ctime(3), strftime(3), and strptime(3).
92
93 Sleeping and setting timers
94 Various system calls and functions allow a program to sleep (suspend
95 execution) for a specified period of time; see nanosleep(2),
96 clock_nanosleep(2), and sleep(3).
97
98 Various system calls allow a process to set a timer that expires at
99 some point in the future, and optionally at repeated intervals; see
100 alarm(2), getitimer(2), timerfd_create(2), and timer_create(2).
101
102 Timer slack
103 Since Linux 2.6.28, it is possible to control the "timer slack" value
104 for a thread. The timer slack is the length of time by which the ker‐
105 nel may delay the wake-up of certain system calls that block with a
106 timeout. Permitting this delay allows the kernel to coalesce wake-up
107 events, thus possibly reducing the number of system wake-ups and saving
108 power. For more details, see the description of PR_SET_TIMERSLACK in
109 prctl(2).
110
112 date(1), time(1), timeout(1), adjtimex(2), alarm(2), clock_gettime(2),
113 clock_nanosleep(2), getitimer(2), getrlimit(2), getrusage(2),
114 gettimeofday(2), nanosleep(2), stat(2), time(2), timer_create(2),
115 timerfd_create(2), times(2), utime(2), adjtime(3), clock(3),
116 clock_getcpuclockid(3), ctime(3), ntp_adjtime(3), ntp_gettime(3),
117 pthread_getcpuclockid(3), sleep(3), strftime(3), strptime(3),
118 timeradd(3), usleep(3), rtc(4), time_namespaces(7), hwclock(8)
119
120
121
122Linux man-pages 6.05 2023-01-22 time(7)