TIME(9)
π TIME(9) β Kernel Developer's Manual, bestie edition π
okay so you're in the 9 section, which is where the kernel developer girlies live, and this page is literally just three global variables that run the whole clock situation. no cap. let's go πβ¨
πΈ NAME πΈ
boottime, time_second, time_uptime β the system time variables, aka the three icons keeping track of when things are happening π
β¨ SYNOPSIS β¨
#include <sys/time.h>
extern struct timeval boottime;
extern time_t time_second;
extern time_t time_uptime;
that's it. that's the whole cast. three externs and a header. slay π
π¦ DESCRIPTION π¦
okay so boom, meet the trio:
boottimeβ this one holds the system boot time. like, the exact moment the system woke up and said "hi bestie, I'm alive" π . it's astruct timeval, so she's got sub-second precision energy.time_secondβ this is the system's βwall timeβ clock, rounded to the second. the vibes clock. the one you glance at. β°time_uptimeβ the number of seconds since boot. not the time of day, just how long have we been up, like a "days since last incident" sign but for your kernel π₯
now here's the tea, bestie π« β if you want the current time and you want it accurate and atomic (no half-updated nonsense, no race conditions sneaking in like a toxic ex), use these instead:
bintime(9), getbintime(9), microtime(9), getmicrotime(9), nanotime(9), and getnanotime(9) β they give you the current time more accurately and in an atomic manner. periodt β¨
and if what you actually want is how much time has elapsed since boot, also accurate, also atomic, hit up:
binuptime(9), getbinuptime(9), microuptime(9), getmicrouptime(9), nanouptime(9), and getnanouptime(9) β these give you the time elapse since boot, more accurately and in an atomic manner π§
butboottime? she's different. theboottimevariable may be read and written without special precautions. lowkey the most chill of the three. no locking drama, no atomic requirements, just vibes π«Ά
π SEE ALSO π
the whole friend group, alphabetized, no one left out:
clock_settime(2)ntp_adjtime(2)settimeofday(2)bintime(9)binuptime(9)getbintime(9)getbinuptime(9)getmicrotime(9)getmicrouptime(9)getnanotime(9)getnanouptime(9)microtime(9)microuptime(9)nanotime(9)nanouptime(9)
and the required reading for the academic girlies π:
- Poul-Henning Kamp, βTimecounters: Efficient and precise timekeeping in SMP kernelsβ, Proceedings of EuroBSDCon 2002, Amsterdam,
/usr/share/doc/papers/timecounter.ascii.gz. - Marshall Kirk McKusick and George V. Neville-Neil, The Design and Implementation of the FreeBSD Operating System, Addison-Wesley, 57-61,65-66, July 2004.
and that's the whole page bestie!! this one came from Debian, dated September 17, 2004, and honestly for a manpage that old she's still serving π go read bintime(9) if you want the atomic upgrade, love u bye πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1994 Christopher G. Demetriou
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms