Hey all,
I need to convert the given boot time which is given in the /proc/stat filesystem in seconds to ctime(). Please look at this code and tell me what I am doing wrong. Thank you.
Code:/* BOOT TIME */ int boot_time; double location_btime; thisFile = fopen("/proc/stat", "r"); while (fgets(Buffer, LB_SIZE + 1, thisFile) != NULL) /* while the feof has not been reached, print info line by line */ { if (strstr(Buffer, "btime") != NULL){ location_btime = ftell(thisFile); break; } } fseek(thisFile, location_btime - 12, SEEK_SET); fscanf(thisFile, "%d\n", &boot_time); printf("boot time in sec: %d\n", ctime(&boot_time)); fclose(thisFile);



LinkBack URL
About LinkBacks


