kai@sp1.csrd.uiuc.edu (Kuck And Associates) (11/28/90)
Here is a short program which, when compiled under Irix 3.2, runs and displays the load averages on both Irix 3.2 and, interestingly, 3.3.1. However, when compiled under Irix 3.3.1, it quits after nlist() with the error message "lseek: Invalid argument". Patrick Wolfe (pwolfe@kai.com, kailand!pwolfe) System Programmer/Operations Manager, Kuck & Associates #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: loadavg.c Makefile # Wrapped by pwolfe@kailand on Tue Nov 27 12:44:18 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'loadavg.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'loadavg.c'\" else echo shar: Extracting \"'loadavg.c'\" \(707 characters\) sed "s/^X//" >'loadavg.c' <<'END_OF_FILE' X#include <stdio.h> X#include <nlist.h> X#include <sys/file.h> X Xchar KmemName[] = "/dev/kmem"; Xchar UnixName[] = "/unix"; Xchar AvenrunSym[] = "avenrun"; X Xmain () X{ Xstruct nlist nl[2]; Xdouble loadav[3]; Xint kmemf; X Xif ((kmemf = open (KmemName, O_RDONLY)) == -1) { X perror ("open"); X exit (1); X } X Xnl[0].n_name = AvenrunSym; Xnlist (UnixName, nl); Xif (nl[0].n_type == 0 || nl[0].n_value == 0) { X perror ("nlist"); X exit (1); X } X Xif (lseek (kmemf, nl[0].n_value, 0) == -1) { X perror ("lseek"); X exit (1); X } X Xif (read (kmemf, loadav, sizeof (loadav)) != sizeof (loadav)) { X perror ("read"); X exit (1); X } X Xprintf ("%04.2f %04.2f %04.2f\n", (double) loadav[0], X (double) loadav[1], (double) loadav[2]); Xexit (0); X} END_OF_FILE if test 707 -ne `wc -c <'loadavg.c'`; then echo shar: \"'loadavg.c'\" unpacked with wrong size! fi # end of 'loadavg.c' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(321 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' XCFLAGS = -g XSHELL = /bin/sh X Xloadavg: loadavg.o Makefile X $(CC) $(CFLAGS) -o loadavg loadavg.o -lmld X @echo "you might need to be root to do the next command" X chgrp sys loadavg X chmod 2755 loadavg X Xclean: X rm -f a.out core mklog loadavg loadavg.shar *.o X Xshar: loadavg.c Makefile X shar loadavg.c Makefile > loadavg.shar END_OF_FILE if test 321 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi echo shar: End of shell archive. exit 0
vjs@rhyolite.wpd.sgi.com (Vernon Schryver) (12/02/90)
In article <1990Nov27.190305.9267@csrd.uiuc.edu>, kai@sp1.csrd.uiuc.edu (Kuck And Associates) writes: > Here is a short program which, when compiled under Irix 3.2, runs and displays > the load averages on both Irix 3.2 and, interestingly, 3.3.1. > However, when compiled under Irix 3.3.1, it quits after nlist() with the error > message "lseek: Invalid argument". There are two main kinds of UNIX systems in the world. Those where the answers you get from nlist() can be used directly on /dev/kmem, and those where you have to strip the sign bit before using lseek(). They are many species in both genera, and no doubt other characteristics in other phyla. Vernon Schryver, vjs@sgi.com