rickert@mp.cs.niu.edu (Neil Rickert) (03/25/91)
In article <1085@ub.d.umn.edu> yyeap@ub.d.umn.edu (Yeap Yuen Pin) writes: >Can someone send me a sample C function that returns the loadavg on >Umax 4.3 (R4.1.0)? Specifically, I like to patch the getla function in >the lastest sendmail package to work on Encore. Thanks. /* * getloadavg() - return load average as integer. * * FOR: Encore multimax UMAX 4.3. * * Extracted from get_stats() (written by John Robert LoVerso) * by Neil Rickert. * * Use inq_stats() to determine boottime, load average * */ #include <sys/param.h> /* */ #include <sys/time.h> /* */ #include <inq_stats/statistics.h> #include <inq_stats/procstats.h> /* * see dimension of ps_nrun[] in procstats.h */ #ifndef PS_NRUNSIZE #define PS_NRUNSIZE 300 #endif /* * Each entry in ps_nrun[] is count of runnable processes sampled every * 5 seconds. period[] contains the number of samples to use for the * intervals of {1,5,15} minutes. cexp[] contains constans for exponential * decay. */ #define period 12 getloadavg(av) double *av; { struct stat_descr Proc_info; struct proc_summary Proc_sum_data; register int i, index, interval; /* * struct to get process summary data, * esp circular buffer containing counts of runnable processes */ Proc_info.sd_next = NULL; Proc_info.sd_subsys = SUBSYS_PROC; Proc_info.sd_type = PROCTYPE_SUMMARY; Proc_info.sd_addr = (char *) &Proc_sum_data; Proc_info.sd_size = sizeof (struct proc_summary); Proc_info.sd_sizeused = 0; /* * fill in Boot_data and Proc_sum_data structures */ if (inq_stats(1, &Proc_info) != 0) { perror("inq_stats"); exit(1); } /* * fastest (inverse shared sum) loop */ index = Proc_sum_data.ps_nrunidx; interval = 0; *av = 0.0; for (; interval < period; interval++) { *av += Proc_sum_data.ps_nrun[index]; if (--index < 0) index = PS_NRUNSIZE-1; } *av /= period; } -- =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= Neil W. Rickert, Computer Science <rickert@cs.niu.edu> Northern Illinois Univ. DeKalb, IL 60115 +1-815-753-6940