/dev/kstat and load average on Solaris 2?

/dev/kstat and load average on Solaris 2?

Post by J. Porter Cla » Mon, 21 Nov 1994 05:24:25

I'm trying to write some code to determine the load average under
Solaris 2.  While trying to get this working--and it's harder than it
looks--I discovered that uptime opens /dev/kstat and (I think) gets the
load average from some ioctls to that device.  I don't have any
documentation that even mentions /dev/kstat.  There is a
/usr/include/kstat.h file that has some interesting things in it, but I
can't tell how to use them.

I'm not sure why uptime would use /dev/kstat (if it does) for the load
average.  There is an avenrun in the kernel anyway, although I have to
admit I haven't managed to figure out how to get to it from a C
program.  I have code that works under SunOS 4.1.3.

I guess I could always do a popen() uptime, but I'd rather not...


1. Problems with kstat, -m64, load average

Hi all,

Solaris 10
gcc 3.4.5 (blastwave package)

The following code works fine when compiled with -m32.  However, when
compiled with -m64 the load average values are totally wonky (as in
huge, wrong numbers).  I tinkered with changing the cast, but that
didn't seem to matter.  Any ideas?

/* loadavgtest.c
 * Built with gcc -Wall -lkstat -m64 loadavgtest.c -o loadavgtest
#include <stdio.h>
#include <kstat.h>

int main(){
   kstat_ctl_t* kc;
   kstat_t* ksp;
   kstat_named_t* kn1;
   kstat_named_t* kn5;
   kstat_named_t* kn15;

   kc = kstat_open();

   if(kc == 0){
      printf("kstat_open() error\n");
      return -1;

   ksp = kstat_lookup(kc, "unix", 0, "system_misc");

   if(ksp == 0){
      printf("kstat_lookup() error\n");
      return -1;

   if(kstat_read(kc,ksp,0) == -1){
      printf("kstat_read() error\n");
      return -1;

   kn1  = kstat_data_lookup(ksp, "avenrun_1min");
   kn5  = kstat_data_lookup(ksp, "avenrun_5min");
   kn15 = kstat_data_lookup(ksp, "avenrun_15min");

   if( (kn1 == 0) || (kn5 == 0) || (kn15 == 0) ){
      printf("kstat_lookup() error\n");
      return -1;

   printf("1 val: %f\n", (double)kn1->value.ul/256);
   printf("5 val: %f\n", (double)kn1->value.ul/256);
   printf("15 val: %f\n", (double)kn1->value.ul/256);

   return 0;



2. How to get the filename from a redirection

3. System Load average: How much load average is good for?

4. Streams: Is it working?

5. average load average?

6. Rfmail released

7. System Load info -Solaris: kstat?

8. FTP and OS5 problem??

9. looking for info on /dev/kstat and kernel symbols un Solaris 2.x

10. percpu load avererages / *real* load averages

11. Load average under Solaris 2 ?

12. Sendmail 8.6.13 + Solaris 2.5 / Load Average Calculation

13. No (load-average) in Solaris-2.6 emacs?