#include #include #include #include "error.h" double timestamp(void) { struct timeval tv; if (gettimeofday(&tv, NULL) == -1) { return -1; } return tv.tv_sec + (tv.tv_usec * 1e-6); } unsigned long get_boot_time(void) { FILE *fp = fopen("/proc/stat", "r"); if (!fp) { error("fopen /proc/stat: %s", strerror(errno)); return 0; } char buf[256]; unsigned long btime = 0; while (fgets(buf, sizeof(buf), fp)) { if (sscanf(buf, "btime %lu", &btime) == 1) { break; } } fclose(fp); return btime; }