summaryrefslogtreecommitdiffstats
path: root/gl/getloadavg.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/getloadavg.c')
-rw-r--r--gl/getloadavg.c258
1 files changed, 128 insertions, 130 deletions
diff --git a/gl/getloadavg.c b/gl/getloadavg.c
index 5a4005c..c6d782b 100644
--- a/gl/getloadavg.c
+++ b/gl/getloadavg.c
@@ -1,8 +1,7 @@
1/* Get the system load averages. 1/* Get the system load averages.
2 2
3 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 3 Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2010 Free Software
4 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free 4 Foundation, Inc.
5 Software Foundation, Inc.
6 5
7 NOTE: The canonical source of this file is maintained with gnulib. 6 NOTE: The canonical source of this file is maintained with gnulib.
8 Bugs can be reported to bug-gnulib@gnu.org. 7 Bugs can be reported to bug-gnulib@gnu.org.
@@ -22,58 +21,58 @@
22 21
23/* Compile-time symbols that this file uses: 22/* Compile-time symbols that this file uses:
24 23
25 HAVE_PSTAT_GETDYNAMIC Define this if your system has the 24 HAVE_PSTAT_GETDYNAMIC Define this if your system has the
26 pstat_getdynamic function. I think it 25 pstat_getdynamic function. I think it
27 is unique to HPUX9. The best way to get the 26 is unique to HPUX9. The best way to get the
28 definition is through the AC_FUNC_GETLOADAVG 27 definition is through the AC_FUNC_GETLOADAVG
29 macro that comes with autoconf 2.13 or newer. 28 macro that comes with autoconf 2.13 or newer.
30 If that isn't an option, then just put 29 If that isn't an option, then just put
31 AC_CHECK_FUNCS(pstat_getdynamic) in your 30 AC_CHECK_FUNCS(pstat_getdynamic) in your
32 configure.in file. 31 configure.in file.
33 HAVE_LIBPERFSTAT Define this if your system has the 32 HAVE_LIBPERFSTAT Define this if your system has the
34 perfstat_cpu_total function in libperfstat (AIX). 33 perfstat_cpu_total function in libperfstat (AIX).
35 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. 34 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist.
36 KERNEL_FILE Name of the kernel file to nlist. 35 KERNEL_FILE Name of the kernel file to nlist.
37 LDAV_CVT() Scale the load average from the kernel. 36 LDAV_CVT() Scale the load average from the kernel.
38 Returns a double. 37 Returns a double.
39 LDAV_SYMBOL Name of kernel symbol giving load average. 38 LDAV_SYMBOL Name of kernel symbol giving load average.
40 LOAD_AVE_TYPE Type of the load average array in the kernel. 39 LOAD_AVE_TYPE Type of the load average array in the kernel.
41 Must be defined unless one of 40 Must be defined unless one of
42 apollo, DGUX, NeXT, or UMAX is defined; 41 apollo, DGUX, NeXT, or UMAX is defined;
43 or we have libkstat; 42 or we have libkstat;
44 otherwise, no load average is available. 43 otherwise, no load average is available.
45 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults 44 HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults
46 to this. 45 to this.
47 NLIST_STRUCT Include nlist.h, not a.out.h, and 46 NLIST_STRUCT Include nlist.h, not a.out.h.
48 the nlist n_name element is a pointer, 47 N_NAME_POINTER The nlist n_name element is a pointer,
49 not an array. 48 not an array.
50 HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'. 49 HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'.
51 LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing 50 LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing
52 load averages. 51 load averages.
53 52
54 Specific system predefines this file uses, aside from setting 53 Specific system predefines this file uses, aside from setting
55 default values if not emacs: 54 default values if not emacs:
56 55
57 apollo 56 apollo
58 BSD Real BSD, not just BSD-like. 57 BSD Real BSD, not just BSD-like.
59 convex 58 convex
60 DGUX 59 DGUX
61 eunice UNIX emulator under VMS. 60 eunice UNIX emulator under VMS.
62 hpux 61 hpux
63 __MSDOS__ No-op for MSDOS. 62 __MSDOS__ No-op for MSDOS.
64 NeXT 63 NeXT
65 sgi 64 sgi
66 sequent Sequent Dynix 3.x.x (BSD) 65 sequent Sequent Dynix 3.x.x (BSD)
67 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) 66 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV)
68 sony_news NEWS-OS (works at least for 4.1C) 67 sony_news NEWS-OS (works at least for 4.1C)
69 UMAX 68 UMAX
70 UMAX4_3 69 UMAX4_3
71 VMS 70 VMS
72 WINDOWS32 No-op for Windows95/NT. 71 WINDOWS32 No-op for Windows95/NT.
73 __linux__ Linux: assumes /proc file system mounted. 72 __linux__ Linux: assumes /proc file system mounted.
74 Support from Michael K. Johnson. 73 Support from Michael K. Johnson.
75 __CYGWIN__ Cygwin emulates linux /proc/loadavg. 74 __CYGWIN__ Cygwin emulates linux /proc/loadavg.
76 __NetBSD__ NetBSD: assumes /kern file system mounted. 75 __NetBSD__ NetBSD: assumes /kern file system mounted.
77 76
78 In addition, to avoid nesting many #ifdefs, we internally set 77 In addition, to avoid nesting many #ifdefs, we internally set
79 LDAV_DONE to indicate that the load average has been computed. 78 LDAV_DONE to indicate that the load average has been computed.
@@ -112,7 +111,6 @@
112# include "c-strtod.h" 111# include "c-strtod.h"
113# include "cloexec.h" 112# include "cloexec.h"
114# include "intprops.h" 113# include "intprops.h"
115# include "xalloc.h"
116 114
117/* The existing Emacs configuration files define a macro called 115/* The existing Emacs configuration files define a macro called
118 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and 116 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
@@ -203,7 +201,7 @@
203 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine 201 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine
204 that with a couple of other things and we'll have a unique match. */ 202 that with a couple of other things and we'll have a unique match. */
205# if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES) 203# if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES)
206# define tek4300 /* Define by emacs, but not by other users. */ 204# define tek4300 /* Define by emacs, but not by other users. */
207# endif 205# endif
208 206
209 207
@@ -317,7 +315,7 @@
317# define FSCALE 65536.0 315# define FSCALE 65536.0
318# endif 316# endif
319 317
320# endif /* Not FSCALE. */ 318# endif /* Not FSCALE. */
321 319
322# if !defined (LDAV_CVT) && defined (FSCALE) 320# if !defined (LDAV_CVT) && defined (FSCALE)
323# define LDAV_CVT(n) (((double) (n)) / FSCALE) 321# define LDAV_CVT(n) (((double) (n)) / FSCALE)
@@ -478,7 +476,7 @@ static unsigned int samples;
478# endif /* UMAX */ 476# endif /* UMAX */
479 477
480# ifdef DGUX 478# ifdef DGUX
481static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ 479static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
482# endif /* DGUX */ 480# endif /* DGUX */
483 481
484# if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE) 482# if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE)
@@ -507,7 +505,7 @@ static kvm_t *kd;
507int 505int
508getloadavg (double loadavg[], int nelem) 506getloadavg (double loadavg[], int nelem)
509{ 507{
510 int elem = 0; /* Return value. */ 508 int elem = 0; /* Return value. */
511 509
512# ifdef NO_GET_LOAD_AVG 510# ifdef NO_GET_LOAD_AVG
513# define LDAV_DONE 511# define LDAV_DONE
@@ -549,16 +547,16 @@ getloadavg (double loadavg[], int nelem)
549 { 547 {
550 kn = kstat_data_lookup (ksp, "avenrun_5min"); 548 kn = kstat_data_lookup (ksp, "avenrun_5min");
551 if (kn != 0) 549 if (kn != 0)
552 { 550 {
553 loadavg[elem++] = (double) kn->value.ul / FSCALE; 551 loadavg[elem++] = (double) kn->value.ul / FSCALE;
554 552
555 if (nelem >= 3) 553 if (nelem >= 3)
556 { 554 {
557 kn = kstat_data_lookup (ksp, "avenrun_15min"); 555 kn = kstat_data_lookup (ksp, "avenrun_15min");
558 if (kn != 0) 556 if (kn != 0)
559 loadavg[elem++] = (double) kn->value.ul / FSCALE; 557 loadavg[elem++] = (double) kn->value.ul / FSCALE;
560 } 558 }
561 } 559 }
562 } 560 }
563 561
564 kstat_close (kc); 562 kstat_close (kc);
@@ -626,11 +624,11 @@ getloadavg (double loadavg[], int nelem)
626 errno = 0; 624 errno = 0;
627 d = c_strtod (ptr, &endptr); 625 d = c_strtod (ptr, &endptr);
628 if (ptr == endptr || (d == 0 && errno != 0)) 626 if (ptr == endptr || (d == 0 && errno != 0))
629 { 627 {
630 if (elem == 0) 628 if (elem == 0)
631 return -1; 629 return -1;
632 break; 630 break;
633 } 631 }
634 loadavg[elem] = d; 632 loadavg[elem] = d;
635 ptr = endptr; 633 ptr = endptr;
636 } 634 }
@@ -655,8 +653,8 @@ getloadavg (double loadavg[], int nelem)
655 if (fp == NULL) 653 if (fp == NULL)
656 return -1; 654 return -1;
657 count = fscanf (fp, "%lu %lu %lu %lu\n", 655 count = fscanf (fp, "%lu %lu %lu %lu\n",
658 &load_ave[0], &load_ave[1], &load_ave[2], 656 &load_ave[0], &load_ave[1], &load_ave[2],
659 &scale); 657 &scale);
660 (void) fclose (fp); 658 (void) fclose (fp);
661 if (count != 4) 659 if (count != 4)
662 return -1; 660 return -1;
@@ -682,21 +680,21 @@ getloadavg (double loadavg[], int nelem)
682 if (!getloadavg_initialized) 680 if (!getloadavg_initialized)
683 { 681 {
684 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) 682 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS)
685 getloadavg_initialized = true; 683 getloadavg_initialized = true;
686 } 684 }
687 685
688 if (getloadavg_initialized) 686 if (getloadavg_initialized)
689 { 687 {
690 info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 688 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
691 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, 689 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
692 (processor_set_info_t) &info, &info_count) 690 (processor_set_info_t) &info, &info_count)
693 != KERN_SUCCESS) 691 != KERN_SUCCESS)
694 getloadavg_initialized = false; 692 getloadavg_initialized = false;
695 else 693 else
696 { 694 {
697 if (nelem > 0) 695 if (nelem > 0)
698 loadavg[elem++] = (double) info.load_average / LOAD_SCALE; 696 loadavg[elem++] = (double) info.load_average / LOAD_SCALE;
699 } 697 }
700 } 698 }
701 699
702 if (!getloadavg_initialized) 700 if (!getloadavg_initialized)
@@ -728,24 +726,24 @@ getloadavg (double loadavg[], int nelem)
728 desc.sd_size = sizeof conf; 726 desc.sd_size = sizeof conf;
729 727
730 if (inq_stats (1, &desc)) 728 if (inq_stats (1, &desc))
731 return -1; 729 return -1;
732 730
733 c = 0; 731 c = 0;
734 for (i = 0; i < conf.config_maxclass; ++i) 732 for (i = 0; i < conf.config_maxclass; ++i)
735 { 733 {
736 struct class_stats stats; 734 struct class_stats stats;
737 bzero ((char *) &stats, sizeof stats); 735 bzero ((char *) &stats, sizeof stats);
738 736
739 desc.sd_type = CPUTYPE_CLASS; 737 desc.sd_type = CPUTYPE_CLASS;
740 desc.sd_objid = i; 738 desc.sd_objid = i;
741 desc.sd_addr = (char *) &stats; 739 desc.sd_addr = (char *) &stats;
742 desc.sd_size = sizeof stats; 740 desc.sd_size = sizeof stats;
743 741
744 if (inq_stats (1, &desc)) 742 if (inq_stats (1, &desc))
745 return -1; 743 return -1;
746 744
747 c += stats.class_numcpus; 745 c += stats.class_numcpus;
748 } 746 }
749 cpus = c; 747 cpus = c;
750 samples = cpus < 2 ? 3 : (2 * cpus / 3); 748 samples = cpus < 2 ? 3 : (2 * cpus / 3);
751 } 749 }
@@ -766,7 +764,7 @@ getloadavg (double loadavg[], int nelem)
766 { 764 {
767 load += proc_sum_data.ps_nrun[j]; 765 load += proc_sum_data.ps_nrun[j];
768 if (j++ == PS_NRUNSIZE) 766 if (j++ == PS_NRUNSIZE)
769 j = 0; 767 j = 0;
770 } 768 }
771 769
772 if (nelem > 0) 770 if (nelem > 0)
@@ -779,8 +777,8 @@ getloadavg (double loadavg[], int nelem)
779 it's not supposed to fail. The first argument is for no 777 it's not supposed to fail. The first argument is for no
780 apparent reason of type `long int *'. */ 778 apparent reason of type `long int *'. */
781 dg_sys_info ((long int *) &load_info, 779 dg_sys_info ((long int *) &load_info,
782 DG_SYS_INFO_LOAD_INFO_TYPE, 780 DG_SYS_INFO_LOAD_INFO_TYPE,
783 DG_SYS_INFO_LOAD_VERSION_0); 781 DG_SYS_INFO_LOAD_VERSION_0);
784 782
785 if (nelem > 0) 783 if (nelem > 0)
786 loadavg[elem++] = load_info.one_minute; 784 loadavg[elem++] = load_info.one_minute;
@@ -824,7 +822,7 @@ getloadavg (double loadavg[], int nelem)
824 = (load_ave.tl_lscale == 0 822 = (load_ave.tl_lscale == 0
825 ? load_ave.tl_avenrun.d[0] 823 ? load_ave.tl_avenrun.d[0]
826 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); 824 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale));
827# endif /* OSF_MIPS */ 825# endif /* OSF_MIPS */
828 826
829# if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32)) 827# if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32))
830# define LDAV_DONE 828# define LDAV_DONE
@@ -844,8 +842,8 @@ getloadavg (double loadavg[], int nelem)
844 for (elem = 0; elem < nelem; elem++) 842 for (elem = 0; elem < nelem; elem++)
845 loadavg[elem] 843 loadavg[elem]
846 = (load_ave.tl_lscale == 0 844 = (load_ave.tl_lscale == 0
847 ? load_ave.tl_avenrun.d[elem] 845 ? load_ave.tl_avenrun.d[elem]
848 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); 846 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale));
849# endif /* OSF_ALPHA */ 847# endif /* OSF_ALPHA */
850 848
851# if ! defined LDAV_DONE && defined __VMS 849# if ! defined LDAV_DONE && defined __VMS
@@ -872,13 +870,13 @@ getloadavg (double loadavg[], int nelem)
872 $DESCRIPTOR (descriptor, "LAV0:"); 870 $DESCRIPTOR (descriptor, "LAV0:");
873# endif 871# endif
874 if (sys$assign (&descriptor, &channel, 0, 0) & 1) 872 if (sys$assign (&descriptor, &channel, 0, 0) & 1)
875 getloadavg_initialized = true; 873 getloadavg_initialized = true;
876 } 874 }
877 875
878 /* Read the load average vector. */ 876 /* Read the load average vector. */
879 if (getloadavg_initialized 877 if (getloadavg_initialized
880 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0, 878 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0,
881 load_ave, 12, 0, 0, 0, 0) & 1)) 879 load_ave, 12, 0, 0, 0, 0) & 1))
882 { 880 {
883 sys$dassgn (channel); 881 sys$dassgn (channel);
884 getloadavg_initialized = false; 882 getloadavg_initialized = false;
@@ -892,7 +890,7 @@ getloadavg (double loadavg[], int nelem)
892 890
893 /* UNIX-specific code -- read the average from /dev/kmem. */ 891 /* UNIX-specific code -- read the average from /dev/kmem. */
894 892
895# define LDAV_PRIVILEGED /* This code requires special installation. */ 893# define LDAV_PRIVILEGED /* This code requires special installation. */
896 894
897 LOAD_AVE_TYPE load_ave[3]; 895 LOAD_AVE_TYPE load_ave[3];
898 896
@@ -900,7 +898,7 @@ getloadavg (double loadavg[], int nelem)
900 if (offset == 0) 898 if (offset == 0)
901 { 899 {
902# ifndef sgi 900# ifndef sgi
903# ifndef NLIST_STRUCT 901# if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER
904 strcpy (nl[0].n_name, LDAV_SYMBOL); 902 strcpy (nl[0].n_name, LDAV_SYMBOL);
905 strcpy (nl[1].n_name, ""); 903 strcpy (nl[1].n_name, "");
906# else /* NLIST_STRUCT */ 904# else /* NLIST_STRUCT */
@@ -916,25 +914,25 @@ getloadavg (double loadavg[], int nelem)
916# ifndef SUNOS_5 914# ifndef SUNOS_5
917 if ( 915 if (
918# if !(defined (_AIX) && !defined (ps2)) 916# if !(defined (_AIX) && !defined (ps2))
919 nlist (KERNEL_FILE, nl) 917 nlist (KERNEL_FILE, nl)
920# else /* _AIX */ 918# else /* _AIX */
921 knlist (nl, 1, sizeof (nl[0])) 919 knlist (nl, 1, sizeof (nl[0]))
922# endif 920# endif
923 >= 0) 921 >= 0)
924 /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ 922 /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */
925 { 923 {
926# ifdef FIXUP_KERNEL_SYMBOL_ADDR 924# ifdef FIXUP_KERNEL_SYMBOL_ADDR
927 FIXUP_KERNEL_SYMBOL_ADDR (nl); 925 FIXUP_KERNEL_SYMBOL_ADDR (nl);
928# endif 926# endif
929 offset = nl[0].n_value; 927 offset = nl[0].n_value;
930 } 928 }
931# endif /* !SUNOS_5 */ 929# endif /* !SUNOS_5 */
932# else /* sgi */ 930# else /* sgi */
933 int ldav_off; 931 int ldav_off;
934 932
935 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); 933 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
936 if (ldav_off != -1) 934 if (ldav_off != -1)
937 offset = (long int) ldav_off & 0x7fffffff; 935 offset = (long int) ldav_off & 0x7fffffff;
938# endif /* sgi */ 936# endif /* sgi */
939 } 937 }
940 938
@@ -944,23 +942,23 @@ getloadavg (double loadavg[], int nelem)
944# ifndef SUNOS_5 942# ifndef SUNOS_5
945 channel = open ("/dev/kmem", O_RDONLY); 943 channel = open ("/dev/kmem", O_RDONLY);
946 if (channel >= 0) 944 if (channel >= 0)
947 { 945 {
948 /* Set the channel to close on exec, so it does not 946 /* Set the channel to close on exec, so it does not
949 litter any child's descriptor table. */ 947 litter any child's descriptor table. */
950 set_cloexec_flag (channel, true); 948 set_cloexec_flag (channel, true);
951 getloadavg_initialized = true; 949 getloadavg_initialized = true;
952 } 950 }
953# else /* SUNOS_5 */ 951# else /* SUNOS_5 */
954 /* We pass 0 for the kernel, corefile, and swapfile names 952 /* We pass 0 for the kernel, corefile, and swapfile names
955 to use the currently running kernel. */ 953 to use the currently running kernel. */
956 kd = kvm_open (0, 0, 0, O_RDONLY, 0); 954 kd = kvm_open (0, 0, 0, O_RDONLY, 0);
957 if (kd != 0) 955 if (kd != 0)
958 { 956 {
959 /* nlist the currently running kernel. */ 957 /* nlist the currently running kernel. */
960 kvm_nlist (kd, nl); 958 kvm_nlist (kd, nl);
961 offset = nl[0].n_value; 959 offset = nl[0].n_value;
962 getloadavg_initialized = true; 960 getloadavg_initialized = true;
963 } 961 }
964# endif /* SUNOS_5 */ 962# endif /* SUNOS_5 */
965 } 963 }
966 964
@@ -970,19 +968,19 @@ getloadavg (double loadavg[], int nelem)
970 /* Try to read the load. */ 968 /* Try to read the load. */
971# ifndef SUNOS_5 969# ifndef SUNOS_5
972 if (lseek (channel, offset, 0) == -1L 970 if (lseek (channel, offset, 0) == -1L
973 || read (channel, (char *) load_ave, sizeof (load_ave)) 971 || read (channel, (char *) load_ave, sizeof (load_ave))
974 != sizeof (load_ave)) 972 != sizeof (load_ave))
975 { 973 {
976 close (channel); 974 close (channel);
977 getloadavg_initialized = false; 975 getloadavg_initialized = false;
978 } 976 }
979# else /* SUNOS_5 */ 977# else /* SUNOS_5 */
980 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) 978 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave))
981 != sizeof (load_ave)) 979 != sizeof (load_ave))
982 { 980 {
983 kvm_close (kd); 981 kvm_close (kd);
984 getloadavg_initialized = false; 982 getloadavg_initialized = false;
985 } 983 }
986# endif /* SUNOS_5 */ 984# endif /* SUNOS_5 */
987 } 985 }
988 986
@@ -1026,24 +1024,24 @@ main (int argc, char **argv)
1026 double avg[3]; 1024 double avg[3];
1027 int loads; 1025 int loads;
1028 1026
1029 errno = 0; /* Don't be misled if it doesn't set errno. */ 1027 errno = 0; /* Don't be misled if it doesn't set errno. */
1030 loads = getloadavg (avg, 3); 1028 loads = getloadavg (avg, 3);
1031 if (loads == -1) 1029 if (loads == -1)
1032 { 1030 {
1033 perror ("Error getting load average"); 1031 perror ("Error getting load average");
1034 return EXIT_FAILURE; 1032 return EXIT_FAILURE;
1035 } 1033 }
1036 if (loads > 0) 1034 if (loads > 0)
1037 printf ("1-minute: %f ", avg[0]); 1035 printf ("1-minute: %f ", avg[0]);
1038 if (loads > 1) 1036 if (loads > 1)
1039 printf ("5-minute: %f ", avg[1]); 1037 printf ("5-minute: %f ", avg[1]);
1040 if (loads > 2) 1038 if (loads > 2)
1041 printf ("15-minute: %f ", avg[2]); 1039 printf ("15-minute: %f ", avg[2]);
1042 if (loads > 0) 1040 if (loads > 0)
1043 putchar ('\n'); 1041 putchar ('\n');
1044 1042
1045 if (naptime == 0) 1043 if (naptime == 0)
1046 break; 1044 break;
1047 sleep (naptime); 1045 sleep (naptime);
1048 } 1046 }
1049 1047