1 /* Get the system load averages.
3 Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2024 Free Software
6 NOTE: The canonical source of this file is maintained with gnulib.
7 Bugs can be reported to bug-gnulib@gnu.org.
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <https://www.gnu.org/licenses/>. */
22 /* Compile-time symbols that this file uses:
24 HAVE_PSTAT_GETDYNAMIC Define this if your system has the
25 pstat_getdynamic function. I think it
26 is unique to HPUX9. The best way to get the
27 definition is through the AC_FUNC_GETLOADAVG
28 macro that comes with autoconf 2.13 or newer.
29 If that isn't an option, then just put
30 AC_CHECK_FUNCS(pstat_getdynamic) in your
32 HAVE_LIBPERFSTAT Define this if your system has the
33 perfstat_cpu_total function in libperfstat (AIX).
34 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist.
35 KERNEL_FILE Name of the kernel file to nlist.
36 LDAV_CVT() Scale the load average from the kernel.
38 LDAV_SYMBOL Name of kernel symbol giving load average.
39 LOAD_AVE_TYPE Type of the load average array in the kernel.
40 Must be defined unless one of
41 apollo, DGUX, NeXT, or UMAX is defined;
43 otherwise, no load average is available.
44 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults
46 NLIST_STRUCT Include nlist.h, not a.out.h.
47 N_NAME_POINTER The nlist n_name element is a pointer,
49 HAVE_STRUCT_NLIST_N_UN_N_NAME 'n_un.n_name' is member of 'struct nlist'.
50 LINUX_LDAV_FILE [__linux__, __ANDROID__, __CYGWIN__]: File
51 containing load averages.
53 Specific system predefines this file uses, aside from setting
54 default values if not emacs:
57 BSD Real BSD, not just BSD-like.
59 eunice UNIX emulator under VMS.
61 __MSDOS__ No-op for MSDOS.
67 _WIN32 Native Windows (possibly also defined on Cygwin)
68 __linux__, __ANDROID__ Linux: assumes /proc file system mounted.
69 Support from Michael K. Johnson.
70 __CYGWIN__ Cygwin emulates linux /proc/loadavg.
71 __NetBSD__ NetBSD: assumes /kern file system mounted.
73 In addition, to avoid nesting many #ifdefs, we internally set
74 LDAV_DONE to indicate that the load average has been computed.
76 We also #define LDAV_PRIVILEGED if a program will require
77 special installation to be able to call getloadavg. */
87 # include <sys/types.h>
90 # include <sys/param.h>
93 # include "intprops.h"
95 # if defined _WIN32 && ! defined __CYGWIN__ && ! defined WINDOWS32
100 /* NeXT in the 2.{0,1,2} releases defines BSD in <sys/param.h>, which
101 conflicts with the definition understood in this file, that this
105 /* NeXT defines FSCALE in <sys/param.h>. However, we take FSCALE being
106 defined to mean that the nlist method should be used, which is not true. */
110 /* Same issues as for NeXT apply to the HURD-based GNU system. */
114 # endif /* __GNU__ */
116 /* Set values that are different from the defaults, which are
117 set a little farther down with #ifndef. */
120 /* Some shorthands. */
122 # if defined (HPUX) && !defined (hpux)
126 # if defined (__hpux) && !defined (hpux)
130 # if defined (__sun) && !defined (sun)
134 # if defined (hp300) && !defined (hpux)
138 # if defined (__SVR4) && !defined (SVR4)
142 # if (defined (sun) && defined (SVR4)) || defined (SOLARIS2)
146 # if defined (__osf__) && (defined (__alpha) || defined (__alpha__))
148 # include <sys/mbuf.h>
149 # include <sys/socket.h>
150 # include <net/route.h>
151 # include <sys/table.h>
152 /* Tru64 4.0D's table.h redefines sys */
156 # if defined (__osf__) && (defined (mips) || defined (__mips__))
158 # include <sys/table.h>
162 /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */
163 # ifndef LOAD_AVE_TYPE
166 # define LOAD_AVE_TYPE long
170 # define LOAD_AVE_TYPE long
174 # define LOAD_AVE_TYPE long
178 # define LOAD_AVE_TYPE long
182 # define LOAD_AVE_TYPE long
185 # if defined _AIX && ! defined HAVE_LIBPERFSTAT
186 # define LOAD_AVE_TYPE long
189 # endif /* No LOAD_AVE_TYPE. */
192 /* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1,
193 according to ghazi@noc.rutgers.edu. */
195 # define FSCALE 1024.0
201 /* SunOS and some others define FSCALE in sys/param.h. */
204 # define FSCALE 2048.0
207 # if defined (MIPS) || defined (SVR4)
212 /* Sometimes both MIPS and sgi are defined, so FSCALE was just defined
213 above under #ifdef MIPS. But we want the sgi value. */
215 # define FSCALE 1000.0
218 # if defined _AIX && !defined HAVE_LIBPERFSTAT
219 # define FSCALE 65536.0
222 # endif /* Not FSCALE. */
224 # if !defined (LDAV_CVT) && defined (FSCALE)
225 # define LDAV_CVT(n) (((double) (n)) / FSCALE)
228 # ifndef NLIST_STRUCT
230 # define NLIST_STRUCT
234 # if defined (sgi) || (defined (mips) && !defined (BSD))
235 # define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31))
239 # if !defined (KERNEL_FILE) && defined (hpux)
240 # define KERNEL_FILE "/hp-ux"
243 # if !defined (KERNEL_FILE) && (defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi))
244 # define KERNEL_FILE "/unix"
248 # if !defined (LDAV_SYMBOL) && (defined (hpux) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (_AIX) && !defined(HAVE_LIBPERFSTAT)))
249 # define LDAV_SYMBOL "avenrun"
252 # ifdef HAVE_UNISTD_H
256 /* LOAD_AVE_TYPE should only get defined if we're going to use the
258 # if !defined (LOAD_AVE_TYPE) && (defined (BSD) || defined (LDAV_CVT) || defined (KERNEL_FILE) || defined (LDAV_SYMBOL))
259 # define LOAD_AVE_TYPE double
262 # ifdef LOAD_AVE_TYPE
265 # if !(defined __linux__ || defined __ANDROID__)
266 # ifndef NLIST_STRUCT
268 # else /* NLIST_STRUCT */
270 # endif /* NLIST_STRUCT */
277 # if defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
278 # include <sys/pstat.h>
282 # define KERNEL_FILE "/vmunix"
283 # endif /* KERNEL_FILE */
286 # define LDAV_SYMBOL "_avenrun"
287 # endif /* LDAV_SYMBOL */
288 # endif /* __linux__ || __ANDROID__ */
294 # include <descrip.h>
296 # include <vms/iodef.h>
301 # define LDAV_CVT(n) ((double) (n))
302 # endif /* !LDAV_CVT */
304 # endif /* LOAD_AVE_TYPE */
306 # if defined HAVE_LIBPERFSTAT
307 # include <sys/protosw.h>
308 # include <libperfstat.h>
309 # include <sys/proc.h>
315 # if defined (__GNU__) && !defined (NeXT)
316 /* Note that NeXT Openstep defines __GNU__ even though it should not. */
317 /* GNU system acts much like NeXT, for load average purposes,
320 # define host_self mach_host_self
324 # ifdef HAVE_MACH_MACH_H
325 # include <mach/mach.h>
332 # include <sys/sysmp.h>
337 # include <sys/time.h>
338 # include <sys/wait.h>
339 # include <sys/syscall.h>
342 # include <machine/cpu.h>
343 # include <inq_stats/statistics.h>
344 # include <inq_stats/sysstats.h>
345 # include <inq_stats/cpustats.h>
346 # include <inq_stats/procstats.h>
347 # else /* Not UMAX_43. */
348 # include <sys/sysdefs.h>
349 # include <sys/statistics.h>
350 # include <sys/sysstats.h>
351 # include <sys/cpudefs.h>
352 # include <sys/cpustats.h>
353 # include <sys/procstats.h>
354 # endif /* Not UMAX_43. */
358 # include <sys/dg_sys_info.h>
361 # if (defined __linux__ || defined __ANDROID__ \
362 || defined __CYGWIN__ || defined SUNOS_5 \
363 || (defined LOAD_AVE_TYPE && ! defined __VMS))
367 /* Avoid static vars inside a function since in HPUX they dump as pure. */
370 static processor_set_t default_set
;
371 static bool getloadavg_initialized
;
375 static unsigned int cpus
= 0;
376 static unsigned int samples
;
380 static struct dg_sys_info_load_info load_info
; /* what-a-mouthful! */
383 # if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE)
384 /* File descriptor open to /dev/kmem or VMS load ave driver. */
386 /* True if channel is valid. */
387 static bool getloadavg_initialized
;
388 /* Offset in kmem to seek to read load average, or 0 means invalid. */
391 # if ! defined __VMS && ! defined sgi && ! (defined __linux__ || defined __ANDROID__)
392 static struct nlist name_list
[2];
397 # endif /* SUNOS_5 */
399 # endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */
401 /* Put the 1 minute, 5 minute and 15 minute load averages
402 into the first NELEM elements of LOADAVG.
403 Return the number written (never more than 3, but may be less than NELEM),
404 or -1 (setting errno) if an error occurred. */
407 getloadavg (double loadavg
[], int nelem
)
409 int elem
= 0; /* Return value. */
411 # ifdef NO_GET_LOAD_AVG
417 # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT) /* Solaris <= 2.6 */
418 /* Use libkstat because we don't have to be root. */
428 ksp
= kstat_lookup (kc
, "unix", 0, "system_misc");
431 if (kstat_read (kc
, ksp
, 0) == -1)
435 kn
= kstat_data_lookup (ksp
, "avenrun_1min");
438 /* Return -1 if no load average information is available. */
444 loadavg
[elem
++] = (double) kn
->value
.ul
/ FSCALE
;
448 kn
= kstat_data_lookup (ksp
, "avenrun_5min");
451 loadavg
[elem
++] = (double) kn
->value
.ul
/ FSCALE
;
455 kn
= kstat_data_lookup (ksp
, "avenrun_15min");
457 loadavg
[elem
++] = (double) kn
->value
.ul
/ FSCALE
;
465 # endif /* HAVE_LIBKSTAT */
467 # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
469 /* Use pstat_getdynamic() because we don't have to be root. */
471 # undef LOAD_AVE_TYPE
473 struct pst_dynamic dyn_info
;
474 if (pstat_getdynamic (&dyn_info
, sizeof (dyn_info
), 0, 0) < 0)
477 loadavg
[elem
++] = dyn_info
.psd_avg_1_min
;
479 loadavg
[elem
++] = dyn_info
.psd_avg_5_min
;
481 loadavg
[elem
++] = dyn_info
.psd_avg_15_min
;
483 # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */
485 # if ! defined LDAV_DONE && defined HAVE_LIBPERFSTAT /* AIX */
487 # undef LOAD_AVE_TYPE
488 /* Use perfstat_cpu_total because we don't have to be root. */
490 perfstat_cpu_total_t cpu_stats
;
491 int result
= perfstat_cpu_total (NULL
, &cpu_stats
, sizeof cpu_stats
, 1);
494 loadavg
[0] = cpu_stats
.loadavg
[0] / (double)(1 << SBITS
);
495 loadavg
[1] = cpu_stats
.loadavg
[1] / (double)(1 << SBITS
);
496 loadavg
[2] = cpu_stats
.loadavg
[2] / (double)(1 << SBITS
);
501 # if !defined (LDAV_DONE) && (defined __linux__ || defined __ANDROID__ || defined __CYGWIN__)
502 /* Linux without glibc, Android, Cygwin */
504 # undef LOAD_AVE_TYPE
506 # ifndef LINUX_LDAV_FILE
507 # define LINUX_LDAV_FILE "/proc/loadavg"
510 char ldavgbuf
[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")];
511 char const *ptr
= ldavgbuf
;
512 int fd
, count
, saved_errno
;
514 fd
= open (LINUX_LDAV_FILE
, O_RDONLY
| O_CLOEXEC
);
517 count
= read (fd
, ldavgbuf
, sizeof ldavgbuf
- 1);
523 ldavgbuf
[count
] = '\0';
525 for (elem
= 0; elem
< nelem
; elem
++)
527 double numerator
= 0;
528 double denominator
= 1;
533 /* Finish if this number is missing, and report an error if all
535 if (! ('0' <= *ptr
&& *ptr
<= '9'))
545 while ('0' <= *ptr
&& *ptr
<= '9')
546 numerator
= 10 * numerator
+ (*ptr
++ - '0');
549 for (ptr
++; '0' <= *ptr
&& *ptr
<= '9'; ptr
++)
550 numerator
= 10 * numerator
+ (*ptr
- '0'), denominator
*= 10;
552 loadavg
[elem
] = numerator
/ denominator
;
557 # endif /* __linux__ || __ANDROID__ || __CYGWIN__ */
559 # if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */
561 # undef LOAD_AVE_TYPE
563 # ifndef NETBSD_LDAV_FILE
564 # define NETBSD_LDAV_FILE "/kern/loadavg"
567 unsigned long int load_ave
[3], scale
;
569 char readbuf
[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1];
570 int fd
= open (NETBSD_LDAV_FILE
, O_RDONLY
| O_CLOEXEC
);
573 int nread
= read (fd
, readbuf
, sizeof readbuf
- 1);
581 readbuf
[nread
] = '\0';
582 count
= sscanf (readbuf
, "%lu %lu %lu %lu\n",
583 &load_ave
[0], &load_ave
[1], &load_ave
[2],
591 for (elem
= 0; elem
< nelem
; elem
++)
592 loadavg
[elem
] = (double) load_ave
[elem
] / (double) scale
;
596 # endif /* __NetBSD__ */
598 # if !defined (LDAV_DONE) && defined (NeXT) /* NeXTStep */
600 /* The NeXT code was adapted from iscreen 3.2. */
603 struct processor_set_basic_info info
;
604 unsigned int info_count
;
606 /* We only know how to get the 1-minute average for this system,
607 so even if the caller asks for more than 1, we only return 1. */
609 if (!getloadavg_initialized
)
611 if (processor_set_default (host_self (), &default_set
) == KERN_SUCCESS
)
612 getloadavg_initialized
= true;
615 if (getloadavg_initialized
)
617 info_count
= PROCESSOR_SET_BASIC_INFO_COUNT
;
618 if (processor_set_info (default_set
, PROCESSOR_SET_BASIC_INFO
, &host
,
619 (processor_set_info_t
) &info
, &info_count
)
621 getloadavg_initialized
= false;
625 loadavg
[elem
++] = (double) info
.load_average
/ LOAD_SCALE
;
629 if (!getloadavg_initialized
)
636 # if !defined (LDAV_DONE) && defined (UMAX)
638 /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not
639 have a /dev/kmem. Information about the workings of the running kernel
640 can be gathered with inq_stats system calls.
641 We only know how to get the 1-minute average for this system. */
643 struct proc_summary proc_sum_data
;
644 struct stat_descr proc_info
;
646 register unsigned int i
, j
;
650 register unsigned int c
, i
;
651 struct cpu_config conf
;
652 struct stat_descr desc
;
655 desc
.sd_subsys
= SUBSYS_CPU
;
656 desc
.sd_type
= CPUTYPE_CONFIG
;
657 desc
.sd_addr
= (char *) &conf
;
658 desc
.sd_size
= sizeof conf
;
660 if (inq_stats (1, &desc
))
664 for (i
= 0; i
< conf
.config_maxclass
; ++i
)
666 struct class_stats stats
;
667 memset (&stats
, 0, sizeof stats
);
669 desc
.sd_type
= CPUTYPE_CLASS
;
671 desc
.sd_addr
= (char *) &stats
;
672 desc
.sd_size
= sizeof stats
;
674 if (inq_stats (1, &desc
))
677 c
+= stats
.class_numcpus
;
680 samples
= cpus
< 2 ? 3 : (2 * cpus
/ 3);
683 proc_info
.sd_next
= 0;
684 proc_info
.sd_subsys
= SUBSYS_PROC
;
685 proc_info
.sd_type
= PROCTYPE_SUMMARY
;
686 proc_info
.sd_addr
= (char *) &proc_sum_data
;
687 proc_info
.sd_size
= sizeof (struct proc_summary
);
688 proc_info
.sd_sizeused
= 0;
690 if (inq_stats (1, &proc_info
) != 0)
693 load
= proc_sum_data
.ps_nrunnable
;
695 for (i
= samples
- 1; i
> 0; --i
)
697 load
+= proc_sum_data
.ps_nrun
[j
];
698 if (j
++ == PS_NRUNSIZE
)
703 loadavg
[elem
++] = load
/ samples
/ cpus
;
706 # if !defined (LDAV_DONE) && defined (DGUX)
708 /* This call can return -1 for an error, but with good args
709 it's not supposed to fail. The first argument is for no
710 apparent reason of type 'long int *'. */
711 dg_sys_info ((long int *) &load_info
,
712 DG_SYS_INFO_LOAD_INFO_TYPE
,
713 DG_SYS_INFO_LOAD_VERSION_0
);
716 loadavg
[elem
++] = load_info
.one_minute
;
718 loadavg
[elem
++] = load_info
.five_minute
;
720 loadavg
[elem
++] = load_info
.fifteen_minute
;
723 # if !defined (LDAV_DONE) && defined (apollo)
725 /* Apollo code from lisch@mentorg.com (Ray Lischner).
727 This system call is not documented. The load average is obtained as
728 three long integers, for the load average over the past minute,
729 five minutes, and fifteen minutes. Each value is a scaled integer,
730 with 16 bits of integer part and 16 bits of fraction part.
732 I'm not sure which operating system first supported this system call,
733 but I know that SR10.2 supports it. */
735 extern void proc1_$
get_loadav ();
736 unsigned long load_ave
[3];
738 proc1_$
get_loadav (load_ave
);
741 loadavg
[elem
++] = load_ave
[0] / 65536.0;
743 loadavg
[elem
++] = load_ave
[1] / 65536.0;
745 loadavg
[elem
++] = load_ave
[2] / 65536.0;
748 # if !defined (LDAV_DONE) && defined (OSF_MIPS)
751 struct tbl_loadavg load_ave
;
752 table (TBL_LOADAVG
, 0, &load_ave
, 1, sizeof (load_ave
));
754 = (load_ave
.tl_lscale
== 0
755 ? load_ave
.tl_avenrun
.d
[0]
756 : (load_ave
.tl_avenrun
.l
[0] / (double) load_ave
.tl_lscale
));
757 # endif /* OSF_MIPS */
759 # if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32))
763 /* A faithful emulation is going to have to be saved for a rainy day. */
764 for ( ; elem
< nelem
; elem
++)
768 # endif /* __MSDOS__ || WINDOWS32 */
770 # if !defined (LDAV_DONE) && defined (OSF_ALPHA) /* OSF/1 */
773 struct tbl_loadavg load_ave
;
774 table (TBL_LOADAVG
, 0, &load_ave
, 1, sizeof (load_ave
));
775 for (elem
= 0; elem
< nelem
; elem
++)
777 = (load_ave
.tl_lscale
== 0
778 ? load_ave
.tl_avenrun
.d
[elem
]
779 : (load_ave
.tl_avenrun
.l
[elem
] / (double) load_ave
.tl_lscale
));
780 # endif /* OSF_ALPHA */
782 # if ! defined LDAV_DONE && defined __VMS /* VMS */
783 /* VMS specific code -- read from the Load Ave driver. */
785 LOAD_AVE_TYPE load_ave
[3];
786 static bool getloadavg_initialized
;
795 /* Ensure that there is a channel open to the load ave device. */
796 if (!getloadavg_initialized
)
798 /* Attempt to open the channel. */
800 descriptor
.dsc$w_length
= 18;
801 descriptor
.dsc$a_pointer
= "$$VMS_LOAD_AVERAGE";
803 $
DESCRIPTOR (descriptor
, "LAV0:");
805 if (sys$
assign (&descriptor
, &channel
, 0, 0) & 1)
806 getloadavg_initialized
= true;
809 /* Read the load average vector. */
810 if (getloadavg_initialized
811 && !(sys$
qiow (0, channel
, IO$_READVBLK
, 0, 0, 0,
812 load_ave
, 12, 0, 0, 0, 0) & 1))
814 sys$
dassgn (channel
);
815 getloadavg_initialized
= false;
818 if (!getloadavg_initialized
)
823 # endif /* ! defined LDAV_DONE && defined __VMS */
825 # if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS
826 /* IRIX, other old systems */
828 /* UNIX-specific code -- read the average from /dev/kmem. */
830 # define LDAV_PRIVILEGED /* This code requires special installation. */
832 LOAD_AVE_TYPE load_ave
[3];
834 /* Get the address of LDAV_SYMBOL. */
838 # if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER
839 strcpy (name_list
[0].n_name
, LDAV_SYMBOL
);
840 strcpy (name_list
[1].n_name
, "");
841 # else /* NLIST_STRUCT */
842 # ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
843 name_list
[0].n_un
.n_name
= LDAV_SYMBOL
;
844 name_list
[1].n_un
.n_name
= 0;
845 # else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */
846 name_list
[0].n_name
= LDAV_SYMBOL
;
847 name_list
[1].n_name
= 0;
848 # endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */
849 # endif /* NLIST_STRUCT */
854 nlist (KERNEL_FILE
, name_list
)
856 knlist (name_list
, 1, sizeof (name_list
[0]))
859 /* Omit "&& name_list[0].n_type != 0 " -- it breaks on Sun386i. */
861 # ifdef FIXUP_KERNEL_SYMBOL_ADDR
862 FIXUP_KERNEL_SYMBOL_ADDR (name_list
);
864 offset
= name_list
[0].n_value
;
866 # endif /* !SUNOS_5 */
868 ptrdiff_t ldav_off
= sysmp (MP_KERNADDR
, MPKA_AVENRUN
);
870 offset
= (long int) ldav_off
& 0x7fffffff;
874 /* Make sure we have /dev/kmem open. */
875 if (!getloadavg_initialized
)
878 int fd
= open ("/dev/kmem", O_RDONLY
| O_CLOEXEC
);
882 getloadavg_initialized
= true;
885 /* We pass 0 for the kernel, corefile, and swapfile names
886 to use the currently running kernel. */
887 kd
= kvm_open (0, 0, 0, O_RDONLY
, 0);
890 /* nlist the currently running kernel. */
891 kvm_nlist (kd
, name_list
);
892 offset
= name_list
[0].n_value
;
893 getloadavg_initialized
= true;
895 # endif /* SUNOS_5 */
898 /* If we can, get the load average values. */
899 if (offset
&& getloadavg_initialized
)
901 /* Try to read the load. */
903 if (lseek (channel
, offset
, 0) == -1L
904 || read (channel
, (char *) load_ave
, sizeof (load_ave
))
905 != sizeof (load_ave
))
908 getloadavg_initialized
= false;
911 if (kvm_read (kd
, offset
, (char *) load_ave
, sizeof (load_ave
))
912 != sizeof (load_ave
))
915 getloadavg_initialized
= false;
917 # endif /* SUNOS_5 */
920 if (offset
== 0 || !getloadavg_initialized
)
925 # endif /* ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS */
927 # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */
929 loadavg
[elem
++] = LDAV_CVT (load_ave
[0]);
931 loadavg
[elem
++] = LDAV_CVT (load_ave
[1]);
933 loadavg
[elem
++] = LDAV_CVT (load_ave
[2]);
936 # endif /* !LDAV_DONE && LOAD_AVE_TYPE */
938 # if !defined LDAV_DONE