Chapter 10. Time
Time serves various purposes in a modern operating system, and many programs need to keep track of it. The kernel measures the passage of time in three different ways:
- Wall time (or real time)
This is the actual time and date in the real world—that is, the time as one would read it on a clock on the wall. Processes use the wall time when interfacing with the user or timestamping an event.
- Process time
This is the time that a process has consumed, either directly in user-space code, or indirectly via the kernel working on the process’ behalf. Processes care about this form of time mostly for profiling and statistics—measuring how long a given operation took, for example. Wall time is misleading for measuring process behavior because, given the multitasking nature of Linux, the process time can be much less than the wall time for a given operation. A process can also spend significant cycles waiting for I/O (particularly keyboard input).
- Monotonic time
This time source is strictly linearly increasing. Most operating systems, Linux included, use the system’s uptime (time since boot). The wall time can change—for example, because the user may set it, and because the system continually adjusts the time for skew—and additional imprecision can be introduced through, say, leap seconds. The system uptime, the other hand, is a deterministic and unchangeable representation of time. The important aspect of a monotonic time source is not the current value, but the guarantee that the ...