Load Averages from ULTRIX?
Jeffrey Mogul
mogul at wrl.dec.com
Wed Dec 5 13:04:25 AEST 1990
In article <3024 at uc.msc.umn.edu> jwabik at uc.msc.umn.edu (Jeff Wabik) writes:
>
>Does anyone know how to retrieve load averages from Ultrix? There
>doesn't seem to be a system call for it. A detailed description or
>hunk of code would be greatly appreciated.
Here's some code to do what you want. It's not quite an explanation,
but with some thought you should be able to understand what is going
on. Note that a lot more error checking could (should) be done, in a
real application.
#! /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 mogul at jove.pa.dec.com on Tue Dec 4 18:02:09 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'\" \(748 characters\)
sed "s/^X//" >'loadavg.c' <<'END_OF_FILE'
X/*
X * Example derived by Jeffrey Mogul/DECWRL from
X * loadst -- print current time and load statistics.
X * -- James Gosling @ CMU, May 1981
X */
X#include <nlist.h>
X#ifdef mips
X#include <sys/fixpoint.h>
X#endif mips
X
struct nlist nl[] = { { "_avenrun" }, { 0 } };
X
main()
X{
X int kmem;
X#ifdef mips
X fix avenrun[3];
X#else
X double avenrun[3];
X#endif mips
X
X if ((kmem = open ("/dev/kmem", 0)) < 0) {
X perror("/dev/kmem");
X exit (1);
X }
X nlist ("/vmunix", nl);
X
X lseek (kmem, (long) nl[0].n_value, 0);
X read (kmem, avenrun, sizeof (avenrun));
X printf ("%.2f, %.2f, %.2f\n",
X#ifdef mips
X FIX_TO_DBL(avenrun[0]), FIX_TO_DBL(avenrun[1]),
X FIX_TO_DBL(avenrun[2]));
X#else
X avenrun[0], avenrun[1], avenrun[2]);
X#endif mips
X}
END_OF_FILE
if test 748 -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'\" \(94 characters\)
sed "s/^X//" >'makefile' <<'END_OF_FILE'
loadavg: loadavg.o
X cc -o loadavg loadavg.o
X
clean:
X rm -f loadavg core *.o a.out *.BAK *.CKP
END_OF_FILE
if test 94 -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
More information about the Comp.unix.ultrix
mailing list