FreeBSD has CLOCK_UPTIME feature for clock_gettime.
https://www.freebsd.org/cgi/man.cgi?query=clock_gettime&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html the functions below make the same job, but clock version is short, fast i think. //------8<----------------------------------------------------------- int64_t uptime_via_clock() { struct timespec ts; clock_gettime(CLOCK_UPTIME , &ts); return ts.tv_sec; } int64_t uptime_via_sysctl() { struct timespec cur_time , boot_time; size_t len = sizeof(struct timespec); sysctlbyname("kern.boottime" , &boot_time , &len , NULL , 0); clock_gettime(CLOCK_REALTIME , &cur_time); return (cur_time.tv_sec - boot_time.tv_sec); } int main() { printf("Uptime Via Clock: %ld\n",uptime_via_clock()); printf("Uptime Via Sysctl: %ld\n",uptime_via_sysctl()); return 0; } //------8<-----------------------------------------------------------