44 lines
1.0 KiB
C
Raw Normal View History

2024-12-01 03:54:43 +00:00
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
void print_datetime(time_t now) {
struct tm *local = localtime(&now);
char buffer[20];
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", local);
printf("%s", buffer);
}
void print_load() {
double loadavg[3];
if (getloadavg(loadavg, 3) == -1) {
perror("getloadavg failed");
return;
}
printf("%.2f %.2f %.2f", loadavg[0], loadavg[1], loadavg[2]);
}
int main(int argc, char *argv[]) {
time_t start_time = time(NULL);
while (true) {
for(int i = 1; i < argc; i++){
printf("%s ", argv[i]);
}
if(argc == 1){
printf("%s", "\rUpdate ");
}
print_datetime(time(NULL));
printf("%s", " since ");
print_datetime(start_time);
printf("%s", ". ");
printf("%s", "Load: ");
print_load();
printf(".%s", "\n");
fflush(stdout);
usleep(30 * 1000 * 1000);
}
return 0;
}