Skip to content

Instantly share code, notes, and snippets.

@nh7a
Created November 14, 2013 18:38
Show Gist options
  • Save nh7a/7472056 to your computer and use it in GitHub Desktop.
Save nh7a/7472056 to your computer and use it in GitHub Desktop.
GetSystemUptime()
int32_t GetSystemUptime()
{
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
size_t mib_size = sizeof(mib) / sizeof(int);
struct timeval boottime;
size_t boottime_size = sizeof(boottime);
if (!sysctl(mib, mib_size, &boottime, &boottime_size, NULL, 0)) {
time_t now;
time(&now);
return now - boottime.tv_sec;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment