status-loadavg/loadavg.c
changeset 1 3e9290bf7249
child 3 dae770da6416
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/status-loadavg/loadavg.c	Mon Oct 20 22:59:08 2014 +0400
@@ -0,0 +1,35 @@
+#define _DEFAULT_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "config.h"
+
+int
+main(void)
+{
+    while (1) {
+        double avgs[3];
+        char *cols[3];
+
+        if (getloadavg(avgs, 3) < 0) {
+            perror("getloadavg");
+            exit(1);
+        }
+        for ( int i = 0; i < 3; i++ ) {
+            if ( avgs[i] <= GREEN )
+                cols[i] = "color='green'";
+            else if ( avgs[i] <= ORANGE )
+                cols[i] = "color='orange'";
+            else
+                cols[i] = "color='red'";
+        }
+
+        printf("<span %s>%.2f</span> <span %s>%.2f</span> <span %s>%.2f</span>\n",
+            cols[0], avgs[0], cols[1], avgs[1], cols[2], avgs[2]);
+        fflush(stdout);
+        sleep(UPDATE_PERIOD);
+    }
+}