summaryrefslogtreecommitdiff
path: root/getloadavg.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1996-09-10 19:50:17 +0000
committerRichard M. Stallman <rms@gnu.org>1996-09-10 19:50:17 +0000
commit5206d3f2bca37af623410dd37f88bf0840ad2572 (patch)
tree117a79743554b949149f528c8f4d8326065ef8f1 /getloadavg.c
parente2da48ca55509fa8f03c310dcd678275bafa9e1b (diff)
downloadgunmake-5206d3f2bca37af623410dd37f88bf0840ad2572.tar.gz
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Diffstat (limited to 'getloadavg.c')
-rw-r--r--getloadavg.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/getloadavg.c b/getloadavg.c
index 1285408..2411e6a 100644
--- a/getloadavg.c
+++ b/getloadavg.c
@@ -391,6 +391,7 @@ extern int errno;
#ifdef SUNOS_5
#include <fcntl.h>
#include <kvm.h>
+#include <kstat.h>
#endif
#ifndef KERNEL_FILE
@@ -516,6 +517,50 @@ getloadavg (loadavg, nelem)
elem = -1;
#endif
+#if !defined (LDAV_DONE) && defined (SUNOS_5)
+/* Use libkstat because we don't have to be root. */
+#define LDAV_DONE
+ kstat_ctl_t *kc;
+ kstat_t *ksp;
+ kstat_named_t *kn;
+
+ kc = kstat_open ();
+ if (kc == 0) return -1;
+ ksp = kstat_lookup (kc, "unix", 0, "system_misc");
+ if (ksp == 0 ) return -1;
+ if (kstat_read (kc, ksp, 0) == -1) return -1;
+
+
+ kn = kstat_data_lookup (ksp, "avenrun_1min");
+ if (kn == 0)
+ {
+ /* Return -1 if no load average information is available. */
+ nelem = 0;
+ elem = -1;
+ }
+
+ if (nelem >= 1)
+ loadavg[elem++] = (double) kn->value.ul/FSCALE;
+
+ if (nelem >= 2)
+ {
+ kn = kstat_data_lookup (ksp, "avenrun_5min");
+ if (kn != 0)
+ {
+ loadavg[elem++] = (double) kn->value.ul/FSCALE;
+
+ if (nelem >= 3)
+ {
+ kn = kstat_data_lookup (ksp, "avenrun_15min");
+ if (kn != 0)
+ loadavg[elem++] = (double) kn->value.ul/FSCALE;
+ }
+ }
+ }
+
+ kstat_close (kc);
+#endif /* SUNOS_5 */
+
#if !defined (LDAV_DONE) && defined (__linux__)
#define LDAV_DONE
#undef LOAD_AVE_TYPE