regexghost-dotfiles

My dotfiles and scripts
git clone git@git.regexghost.com/regexghost-dotfiles.git
Log | Files | Refs | README

uptime.c (813B)


      1 #include <sys/sysinfo.h>
      2 #include <stdio.h>
      3 #include <time.h>
      4 
      5 int main() {
      6 	struct sysinfo info;
      7 	
      8 	if (sysinfo(&info) != 0) {
      9 		printf("Error");
     10 		return 1;
     11 	}
     12 	
     13 	//printf("Uptime: %ld\n", info.uptime);
     14 	//return 0;
     15 	
     16 	
     17 	int hours = info.uptime/3600;
     18 	int minutes = (info.uptime - hours * 3600)/60;
     19 	
     20 	printf("%02d:%02d\n", hours, minutes);
     21 
     22 	return 1;
     23 	float f_load = 1.f / (1 << SI_LOAD_SHIFT);
     24 	
     25 	time_t bootTime = time(NULL) - info.uptime + 1;
     26 	struct tm* bootTimeFormatted;
     27 	bootTimeFormatted = localtime(&bootTime);
     28 	
     29 	printf("%s", asctime(bootTimeFormatted));
     30 	time_t a;
     31 	time(&a);
     32 	//printf("%d\n", a);
     33 	
     34 	
     35 	//printf("<tool>Load Average (1m): %0.2f\nLoad Average (5m): %0.2f\nLoad Average (15m): %0.2f</tool>", info.loads[0] * f_load, info.loads[1] * f_load, info.loads[2] * f_load);
     36 	//printf("\n");
     37 }