1 /* Get the system load averages.
2 Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997
3 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 /* Compile-time symbols that this file uses:
22 HAVE_PSTAT_GETDYNAMIC Define this if your system has the
23 pstat_getdynamic function. I think it
24 is unique to HPUX9. The best way to get the
25 definition is through the AC_FUNC_GETLOADAVG
26 macro that comes with autoconf 2.13 or newer.
27 If that isn't an option, then just put
28 AC_CHECK_FUNCS(pstat_getdynamic) in your
30 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist.
31 KERNEL_FILE Pathname of the kernel to nlist.
32 LDAV_CVT() Scale the load average from the kernel.
34 LDAV_SYMBOL Name of kernel symbol giving load average.
35 LOAD_AVE_TYPE Type of the load average array in the kernel.
36 Must be defined unless one of
37 apollo, DGUX, NeXT, or UMAX is defined;
38 otherwise, no load average is available.
39 NLIST_NAME_UNION struct nlist has an n_un member, not n_name.
40 LINUX_LDAV_FILE [__linux__]: File containing load averages.
42 Specific system predefines this file uses, aside from setting
43 default values if not emacs:
46 BSD Real BSD, not just BSD-like.
49 eunice UNIX emulator under VMS.
51 __MSDOS__ No-op for MSDOS.
54 sequent Sequent Dynix 3.x.x (BSD)
55 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV)
56 sony_news NEWS-OS (works at least for 4.1C)
60 WINDOWS32 No-op for Windows95/NT.
61 __linux__ Linux: assumes /proc filesystem mounted.
62 Support from Michael K. Johnson.
63 __NetBSD__ NetBSD: assumes /kern filesystem mounted.
65 In addition, to avoid nesting many #ifdefs, we internally set
66 LDAV_DONE to indicate that the load average has been computed.
68 We also #define LDAV_PRIVILEGED if a program will require
69 special installation to be able to call getloadavg. */
71 /* This should always be first. */
76 #include <sys/types.h>
78 /* Both the Emacs and non-Emacs sections want this. Some
79 configuration files' definitions for the LOAD_AVE_CVT macro (like
80 sparc.h's) use macros like FSCALE, defined here. */
82 # include <sys/param.h>
86 /* Exclude all the code except the test program at the end
87 if the system has its own `getloadavg' function.
89 The declaration of `errno' is needed by the test program
90 as well as the function itself, so it comes first. */
102 # define setlocale(Category, Locale) /* empty */
105 #ifndef HAVE_GETLOADAVG
107 /* The existing Emacs configuration files define a macro called
108 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
109 returns the load average multiplied by 100. What we actually want
110 is a macro called LDAV_CVT, which returns the load average as an
113 For backwards compatibility, we'll define LDAV_CVT in terms of
114 LOAD_AVE_CVT, but future machine config files should just define
115 LDAV_CVT directly. */
117 # if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT)
118 # define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0)
121 # if !defined (BSD) && defined (ultrix)
122 /* Ultrix behaves like BSD on Vaxen. */
127 /* NeXT in the 2.{0,1,2} releases defines BSD in <sys/param.h>, which
128 conflicts with the definition understood in this file, that this
132 /* NeXT defines FSCALE in <sys/param.h>. However, we take FSCALE being
133 defined to mean that the nlist method should be used, which is not true. */
137 /* Set values that are different from the defaults, which are
138 set a little farther down with #ifndef. */
141 /* Some shorthands. */
143 # if defined (HPUX) && !defined (hpux)
147 # if defined (__hpux) && !defined (hpux)
151 # if defined (__sun) && !defined (sun)
155 # if defined(hp300) && !defined(hpux)
159 # if defined(ultrix) && defined(mips)
163 # if defined (__SVR4) && !defined (SVR4)
167 # if (defined(sun) && defined(SVR4)) || defined (SOLARIS2)
171 # if defined (__osf__) && (defined (__alpha) || defined (__alpha__))
173 # include <sys/mbuf.h>
174 # include <sys/socket.h>
175 # include <net/route.h>
176 # include <sys/table.h>
179 # if defined (__osf__) && (defined (mips) || defined (__mips__))
181 # include <sys/table.h>
184 /* UTek's /bin/cc on the 4300 has no architecture specific cpp define by
185 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine
186 that with a couple of other things and we'll have a unique match. */
187 # if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES)
188 # define tek4300 /* Define by emacs, but not by other users. */
192 /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */
193 # ifndef LOAD_AVE_TYPE
196 # define LOAD_AVE_TYPE long
200 # define LOAD_AVE_TYPE long
204 # define LOAD_AVE_TYPE long
208 # define LOAD_AVE_TYPE long
212 # define LOAD_AVE_TYPE long
216 # define LOAD_AVE_TYPE long
220 # define LOAD_AVE_TYPE long
224 # define LOAD_AVE_TYPE long
228 # define LOAD_AVE_TYPE long
231 # if defined (ardent) && defined (titan)
232 # define LOAD_AVE_TYPE long
236 # define LOAD_AVE_TYPE long
239 # if defined(alliant) && defined(i860) /* Alliant FX/2800 */
240 # define LOAD_AVE_TYPE long
244 # define LOAD_AVE_TYPE long
248 # define LOAD_AVE_TYPE double
250 # define LDAV_CVT(n) (n)
254 # endif /* No LOAD_AVE_TYPE. */
257 /* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1,
258 according to ghazi@noc.rutgers.edu. */
260 # define FSCALE 1024.0
263 # if defined(alliant) && defined(i860) /* Alliant FX/2800 */
264 /* <sys/param.h> defines an incorrect value for FSCALE on an
265 Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */
267 # define FSCALE 100.0
273 /* SunOS and some others define FSCALE in sys/param.h. */
276 # define FSCALE 2048.0
279 # if defined(MIPS) || defined(SVR4) || defined(decstation)
283 # if defined (sgi) || defined (sequent)
284 /* Sometimes both MIPS and sgi are defined, so FSCALE was just defined
285 above under #ifdef MIPS. But we want the sgi value. */
287 # define FSCALE 1000.0
290 # if defined (ardent) && defined (titan)
291 # define FSCALE 65536.0
295 # define FSCALE 100.0
299 # define FSCALE 65536.0
302 # endif /* Not FSCALE. */
304 # if !defined (LDAV_CVT) && defined (FSCALE)
305 # define LDAV_CVT(n) (((double) (n)) / FSCALE)
308 # if defined(sgi) || (defined(mips) && !defined(BSD))
309 # define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31))
313 # if !defined (KERNEL_FILE) && defined (sequent)
314 # define KERNEL_FILE "/dynix"
317 # if !defined (KERNEL_FILE) && defined (hpux)
318 # define KERNEL_FILE "/hp-ux"
321 # if !defined(KERNEL_FILE) && (defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi) || (defined (ardent) && defined (titan)))
322 # define KERNEL_FILE "/unix"
326 # if !defined (LDAV_SYMBOL) && defined (alliant)
327 # define LDAV_SYMBOL "_Loadavg"
330 # if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX))
331 # define LDAV_SYMBOL "avenrun"
334 # ifdef HAVE_UNISTD_H
340 /* LOAD_AVE_TYPE should only get defined if we're going to use the
342 # if !defined(LOAD_AVE_TYPE) && (defined(BSD) || defined(LDAV_CVT) || defined(KERNEL_FILE) || defined(LDAV_SYMBOL))
343 # define LOAD_AVE_TYPE double
346 # ifdef LOAD_AVE_TYPE
350 # ifndef HAVE_NLIST_H
352 # else /* HAVE_NLIST_H */
354 # endif /* HAVE_NLIST_H */
362 # if defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
363 # include <sys/pstat.h>
367 # define KERNEL_FILE "/vmunix"
368 # endif /* KERNEL_FILE */
371 # define LDAV_SYMBOL "_avenrun"
372 # endif /* LDAV_SYMBOL */
373 # endif /* __linux__ */
379 # include <descrip.h>
381 # include <vms/iodef.h>
386 # define LDAV_CVT(n) ((double) (n))
387 # endif /* !LDAV_CVT */
389 # endif /* LOAD_AVE_TYPE */
391 # if defined(__GNU__) && !defined (NeXT)
392 /* Note that NeXT Openstep defines __GNU__ even though it should not. */
393 /* GNU system acts much like NeXT, for load average purposes,
396 # define host_self mach_host_self
400 # ifdef HAVE_MACH_MACH_H
401 # include <mach/mach.h>
408 # include <sys/sysmp.h>
414 # include <sys/time.h>
415 # include <sys/wait.h>
416 # include <sys/syscall.h>
419 # include <machine/cpu.h>
420 # include <inq_stats/statistics.h>
421 # include <inq_stats/sysstats.h>
422 # include <inq_stats/cpustats.h>
423 # include <inq_stats/procstats.h>
424 # else /* Not UMAX_43. */
425 # include <sys/sysdefs.h>
426 # include <sys/statistics.h>
427 # include <sys/sysstats.h>
428 # include <sys/cpudefs.h>
429 # include <sys/cpustats.h>
430 # include <sys/procstats.h>
431 # endif /* Not UMAX_43. */
435 # include <sys/dg_sys_info.h>
438 # if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION)
441 # include <sys/file.h>
444 /* Avoid static vars inside a function since in HPUX they dump as pure. */
447 static processor_set_t default_set;
448 static int getloadavg_initialized;
452 static unsigned int cpus = 0;
453 static unsigned int samples;
457 static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
460 # ifdef LOAD_AVE_TYPE
461 /* File descriptor open to /dev/kmem or VMS load ave driver. */
463 /* Nonzero iff channel is valid. */
464 static int getloadavg_initialized;
465 /* Offset in kmem to seek to read load average, or 0 means invalid. */
468 # if !defined(VMS) && !defined(sgi) && !defined(__linux__)
469 static struct nlist nl[2];
470 # endif /* Not VMS or sgi */
474 # endif /* SUNOS_5 */
476 # endif /* LOAD_AVE_TYPE */
478 /* Put the 1 minute, 5 minute and 15 minute load averages
479 into the first NELEM elements of LOADAVG.
480 Return the number written (never more than 3, but may be less than NELEM),
481 or -1 if an error occurred. */
484 getloadavg (loadavg, nelem)
488 int elem = 0; /* Return value. */
490 # ifdef NO_GET_LOAD_AVG
492 /* Set errno to zero to indicate that there was no particular error;
493 this function just can't work at all on this system. */
498 # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT)
499 /* Use libkstat because we don't have to be root. */
508 ksp = kstat_lookup (kc, "unix", 0, "system_misc");
511 if (kstat_read (kc, ksp, 0) == -1)
515 kn = kstat_data_lookup (ksp, "avenrun_1min");
518 /* Return -1 if no load average information is available. */
524 loadavg[elem++] = (double) kn->value.ul/FSCALE;
528 kn = kstat_data_lookup (ksp, "avenrun_5min");
531 loadavg[elem++] = (double) kn->value.ul/FSCALE;
535 kn = kstat_data_lookup (ksp, "avenrun_15min");
537 loadavg[elem++] = (double) kn->value.ul/FSCALE;
543 # endif /* HAVE_LIBKSTAT */
545 # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
546 /* Use pstat_getdynamic() because we don't have to be root. */
548 # undef LOAD_AVE_TYPE
550 struct pst_dynamic dyn_info;
551 if (pstat_getdynamic (&dyn_info, sizeof (dyn_info), 0, 0) < 0)
554 loadavg[elem++] = dyn_info.psd_avg_1_min;
556 loadavg[elem++] = dyn_info.psd_avg_5_min;
558 loadavg[elem++] = dyn_info.psd_avg_15_min;
560 # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */
562 # if !defined (LDAV_DONE) && defined (__linux__)
564 # undef LOAD_AVE_TYPE
566 # ifndef LINUX_LDAV_FILE
567 # define LINUX_LDAV_FILE "/proc/loadavg"
574 fd = open (LINUX_LDAV_FILE, O_RDONLY);
577 count = read (fd, ldavgbuf, 40);
582 /* The following sscanf must use the C locale. */
583 setlocale (LC_NUMERIC, "C");
584 count = sscanf (ldavgbuf, "%lf %lf %lf",
585 &load_ave[0], &load_ave[1], &load_ave[2]);
586 setlocale (LC_NUMERIC, "");
590 for (elem = 0; elem < nelem && elem < count; elem++)
591 loadavg[elem] = load_ave[elem];
595 # endif /* __linux__ */
597 # if !defined (LDAV_DONE) && defined (__NetBSD__)
599 # undef LOAD_AVE_TYPE
601 # ifndef NETBSD_LDAV_FILE
602 # define NETBSD_LDAV_FILE "/kern/loadavg"
605 unsigned long int load_ave[3], scale;
609 fp = fopen (NETBSD_LDAV_FILE, "r");
612 count = fscanf (fp, "%lu %lu %lu %lu\n",
613 &load_ave[0], &load_ave[1], &load_ave[2],
619 for (elem = 0; elem < nelem; elem++)
620 loadavg[elem] = (double) load_ave[elem] / (double) scale;
624 # endif /* __NetBSD__ */
626 # if !defined (LDAV_DONE) && defined (NeXT)
628 /* The NeXT code was adapted from iscreen 3.2. */
631 struct processor_set_basic_info info;
634 /* We only know how to get the 1-minute average for this system,
635 so even if the caller asks for more than 1, we only return 1. */
637 if (!getloadavg_initialized)
639 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS)
640 getloadavg_initialized = 1;
643 if (getloadavg_initialized)
645 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
646 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
647 (processor_set_info_t) &info, &info_count)
649 getloadavg_initialized = 0;
653 loadavg[elem++] = (double) info.load_average / LOAD_SCALE;
657 if (!getloadavg_initialized)
661 # if !defined (LDAV_DONE) && defined (UMAX)
663 /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not
664 have a /dev/kmem. Information about the workings of the running kernel
665 can be gathered with inq_stats system calls.
666 We only know how to get the 1-minute average for this system. */
668 struct proc_summary proc_sum_data;
669 struct stat_descr proc_info;
671 register unsigned int i, j;
675 register unsigned int c, i;
676 struct cpu_config conf;
677 struct stat_descr desc;
680 desc.sd_subsys = SUBSYS_CPU;
681 desc.sd_type = CPUTYPE_CONFIG;
682 desc.sd_addr = (char *) &conf;
683 desc.sd_size = sizeof conf;
685 if (inq_stats (1, &desc))
689 for (i = 0; i < conf.config_maxclass; ++i)
691 struct class_stats stats;
692 bzero ((char *) &stats, sizeof stats);
694 desc.sd_type = CPUTYPE_CLASS;
696 desc.sd_addr = (char *) &stats;
697 desc.sd_size = sizeof stats;
699 if (inq_stats (1, &desc))
702 c += stats.class_numcpus;
705 samples = cpus < 2 ? 3 : (2 * cpus / 3);
708 proc_info.sd_next = 0;
709 proc_info.sd_subsys = SUBSYS_PROC;
710 proc_info.sd_type = PROCTYPE_SUMMARY;
711 proc_info.sd_addr = (char *) &proc_sum_data;
712 proc_info.sd_size = sizeof (struct proc_summary);
713 proc_info.sd_sizeused = 0;
715 if (inq_stats (1, &proc_info) != 0)
718 load = proc_sum_data.ps_nrunnable;
720 for (i = samples - 1; i > 0; --i)
722 load += proc_sum_data.ps_nrun[j];
723 if (j++ == PS_NRUNSIZE)
728 loadavg[elem++] = load / samples / cpus;
731 # if !defined (LDAV_DONE) && defined (DGUX)
733 /* This call can return -1 for an error, but with good args
734 it's not supposed to fail. The first argument is for no
735 apparent reason of type `long int *'. */
736 dg_sys_info ((long int *) &load_info,
737 DG_SYS_INFO_LOAD_INFO_TYPE,
738 DG_SYS_INFO_LOAD_VERSION_0);
741 loadavg[elem++] = load_info.one_minute;
743 loadavg[elem++] = load_info.five_minute;
745 loadavg[elem++] = load_info.fifteen_minute;
748 # if !defined (LDAV_DONE) && defined (apollo)
750 /* Apollo code from lisch@mentorg.com (Ray Lischner).
752 This system call is not documented. The load average is obtained as
753 three long integers, for the load average over the past minute,
754 five minutes, and fifteen minutes. Each value is a scaled integer,
755 with 16 bits of integer part and 16 bits of fraction part.
757 I'm not sure which operating system first supported this system call,
758 but I know that SR10.2 supports it. */
760 extern void proc1_$get_loadav ();
761 unsigned long load_ave[3];
763 proc1_$get_loadav (load_ave);
766 loadavg[elem++] = load_ave[0] / 65536.0;
768 loadavg[elem++] = load_ave[1] / 65536.0;
770 loadavg[elem++] = load_ave[2] / 65536.0;
773 # if !defined (LDAV_DONE) && defined (OSF_MIPS)
776 struct tbl_loadavg load_ave;
777 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
779 = (load_ave.tl_lscale == 0
780 ? load_ave.tl_avenrun.d[0]
781 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale));
782 # endif /* OSF_MIPS */
784 # if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32))
787 /* A faithful emulation is going to have to be saved for a rainy day. */
788 for ( ; elem < nelem; elem++)
792 # endif /* __MSDOS__ || WINDOWS32 */
794 # if !defined (LDAV_DONE) && defined (OSF_ALPHA)
797 struct tbl_loadavg load_ave;
798 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
799 for (elem = 0; elem < nelem; elem++)
801 = (load_ave.tl_lscale == 0
802 ? load_ave.tl_avenrun.d[elem]
803 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale));
804 # endif /* OSF_ALPHA */
806 # if !defined (LDAV_DONE) && defined (VMS)
807 /* VMS specific code -- read from the Load Ave driver. */
809 LOAD_AVE_TYPE load_ave[3];
810 static int getloadavg_initialized = 0;
819 /* Ensure that there is a channel open to the load ave device. */
820 if (!getloadavg_initialized)
822 /* Attempt to open the channel. */
824 descriptor.dsc$w_length = 18;
825 descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE";
827 $DESCRIPTOR (descriptor, "LAV0:");
829 if (sys$assign (&descriptor, &channel, 0, 0) & 1)
830 getloadavg_initialized = 1;
833 /* Read the load average vector. */
834 if (getloadavg_initialized
835 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0,
836 load_ave, 12, 0, 0, 0, 0) & 1))
838 sys$dassgn (channel);
839 getloadavg_initialized = 0;
842 if (!getloadavg_initialized)
846 # if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) && !defined(VMS)
848 /* UNIX-specific code -- read the average from /dev/kmem. */
850 # define LDAV_PRIVILEGED /* This code requires special installation. */
852 LOAD_AVE_TYPE load_ave[3];
854 /* Get the address of LDAV_SYMBOL. */
858 # ifndef HAVE_NLIST_H
859 strcpy (nl[0].n_name, LDAV_SYMBOL);
860 strcpy (nl[1].n_name, "");
861 # else /* HAVE_NLIST_H */
862 # ifdef NLIST_NAME_UNION
863 nl[0].n_un.n_name = LDAV_SYMBOL;
864 nl[1].n_un.n_name = 0;
865 # else /* not NLIST_NAME_UNION */
866 nl[0].n_name = LDAV_SYMBOL;
868 # endif /* not NLIST_NAME_UNION */
869 # endif /* HAVE_NLIST_H */
873 # if !(defined (_AIX) && !defined (ps2))
874 nlist (KERNEL_FILE, nl)
876 knlist (nl, 1, sizeof (nl[0]))
879 /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */
881 # ifdef FIXUP_KERNEL_SYMBOL_ADDR
882 FIXUP_KERNEL_SYMBOL_ADDR (nl);
884 offset = nl[0].n_value;
886 # endif /* !SUNOS_5 */
890 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
892 offset = (long) ldav_off & 0x7fffffff;
896 /* Make sure we have /dev/kmem open. */
897 if (!getloadavg_initialized)
900 channel = open ("/dev/kmem", 0);
903 /* Set the channel to close on exec, so it does not
904 litter any child's descriptor table. */
907 # define FD_CLOEXEC 1
909 (void) fcntl (channel, F_SETFD, FD_CLOEXEC);
911 getloadavg_initialized = 1;
914 /* We pass 0 for the kernel, corefile, and swapfile names
915 to use the currently running kernel. */
916 kd = kvm_open (0, 0, 0, O_RDONLY, 0);
919 /* nlist the currently running kernel. */
921 offset = nl[0].n_value;
922 getloadavg_initialized = 1;
924 # endif /* SUNOS_5 */
927 /* If we can, get the load average values. */
928 if (offset && getloadavg_initialized)
930 /* Try to read the load. */
932 if (lseek (channel, offset, 0) == -1L
933 || read (channel, (char *) load_ave, sizeof (load_ave))
934 != sizeof (load_ave))
937 getloadavg_initialized = 0;
940 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave))
941 != sizeof (load_ave))
944 getloadavg_initialized = 0;
946 # endif /* SUNOS_5 */
949 if (offset == 0 || !getloadavg_initialized)
951 # endif /* LOAD_AVE_TYPE and not VMS */
953 # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */
955 loadavg[elem++] = LDAV_CVT (load_ave[0]);
957 loadavg[elem++] = LDAV_CVT (load_ave[1]);
959 loadavg[elem++] = LDAV_CVT (load_ave[2]);
962 # endif /* !LDAV_DONE && LOAD_AVE_TYPE */
967 /* Set errno to zero to indicate that there was no particular error;
968 this function just can't work at all on this system. */
974 #endif /* ! HAVE_GETLOADAVG */
985 naptime = atoi (argv[1]);
992 errno = 0; /* Don't be misled if it doesn't set errno. */
993 loads = getloadavg (avg, 3);
996 perror ("Error getting load average");
1000 printf ("1-minute: %f ", avg[0]);
1002 printf ("5-minute: %f ", avg[1]);
1004 printf ("15-minute: %f ", avg[2]);