comparison src/getloadavg.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 59463afc5666
children 850242ba4a81
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
535 #endif 535 #endif
536 536
537 #ifdef XEMACS 537 #ifdef XEMACS
538 #if ! defined (LDAV_DONE) && defined (HAVE_KSTAT_H) && defined (HAVE_LIBKSTAT) 538 #if ! defined (LDAV_DONE) && defined (HAVE_KSTAT_H) && defined (HAVE_LIBKSTAT)
539 #define LDAV_DONE 539 #define LDAV_DONE
540 540
541 /* getloadavg is best implemented using kstat (kernel stats), 541 /* getloadavg is best implemented using kstat (kernel stats),
542 on systems (like SunOS5) that support it, 542 on systems (like SunOS5) that support it,
543 since you don't have to be superusers to use it. 543 since you don't have to be superusers to use it.
544 Thanks to Zlatko Calusic <zcalusic@srce.hr>. 544 Thanks to Zlatko Calusic <zcalusic@srce.hr>.
545 Integrated to XEmacs by Hrvoje Niksic <hniksic@srce.hr>. */ 545 Integrated to XEmacs by Hrvoje Niksic <hniksic@srce.hr>. */
557 ksp = kstat_lookup(kc, "unix", 0, "system_misc"); 557 ksp = kstat_lookup(kc, "unix", 0, "system_misc");
558 if (!ksp) 558 if (!ksp)
559 return -1; 559 return -1;
560 if (kstat_read(kc, ksp, ksp->ks_data) < 0) 560 if (kstat_read(kc, ksp, ksp->ks_data) < 0)
561 return -1; 561 return -1;
562 buf = malloc(ksp->ks_data_size); 562 buf = (kstat_named_t *) malloc (ksp->ks_data_size);
563 if (!buf) 563 if (!buf)
564 return -1; 564 return -1;
565 memcpy(buf, ksp->ks_data, ksp->ks_data_size); 565 memcpy(buf, ksp->ks_data, ksp->ks_data_size);
566 if (nelem > 3) 566 if (nelem > 3)
567 nelem = 3; 567 nelem = 3;
568 for (elem = 0; elem < nelem; elem++) 568 for (elem = 0; elem < nelem; elem++)
569 loadavg[elem] = (buf + 6 + elem)->value.ul / 256.0; 569 loadavg[elem] = (buf + 6 + elem)->value.ul / 256.0;
570 free(buf); 570 free(buf);
571 571
572 #endif /* HAVE_KSTAT_H && HAVE_LIBKSTAT */ 572 #endif /* HAVE_KSTAT_H && HAVE_LIBKSTAT */
573 573
574 #if !defined (LDAV_DONE) && defined (HAVE_SYS_PSTAT_H) 574 #if !defined (LDAV_DONE) && defined (HAVE_SYS_PSTAT_H)
575 #define LDAV_DONE 575 #define LDAV_DONE
576 /* This is totally undocumented, and is not guaranteed to work, but 576 /* This is totally undocumented, and is not guaranteed to work, but