Created
December 23, 2009 15:32
-
-
Save skreuzer/262576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <sys/param.h> | |
#include <sys/sysctl.h> | |
int | |
main() | |
{ | |
time_t uptime; | |
time_t now; | |
size_t size; | |
int mib[2]; | |
struct timeval boottime; | |
time(&now); | |
size = sizeof(boottime); | |
mib[0] = CTL_KERN; | |
mib[1] = KERN_BOOTTIME; | |
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) { | |
uptime = now - boottime.tv_sec; | |
printf("%d\n", uptime); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment