Avenrun in IRIX 3.2

Andrew Cherenson arc at SGI.SGI.COM
Fri Dec 1 11:55:31 AEST 1989


In article <12452 at cgl.ucsf.EDU> srp at cgl.ucsf.edu (Scott R. Presnell) writes:
>Hi all,
>	Avenrun seems to be available in the IRIX 3.2 kernel as an array of
>longs.  But as in the Sun kernel it appears to need a scaling... 1024 seems
>about right.  Does anyone know what and/or where the appropriate constant
>might be found?

1024 is correct. Here's a sample program to access avenrun.

------ Cut here ----------------------------------------------
/*
 * loadavg.c --
 *
 *	Prints 1, 5, and 15 minute load averages for an 
 *	IRIS-4D running	IRIX 3.2.
 *
 *	As root, do
 *		cc loadavg.c -lmld -o loadavg
 *		chgrp sys loadavg
 *		chmod 2555 loadavg	
 *	(It must be setgid sys to read /dev/kmem.)
 *
 *	This file is in the public domain.
 *	THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
 *	INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS
 *	FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING,
 *	USAGE OR TRADE PRACTICE.
 *	
 *	This file is provided with no support and without any
 *	obligation on the part of Silicon Graphics, Inc. to assist in
 *	its use, correction, modification or enhancement.
 *	
 *	SILICON GRAPHICS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO
 *	THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
 *	THIS FILE OR ANY PART THEREOF.
 *	
 *	In no event will Silicon Graphics, Inc. be liable for any lost
 *	revenue or profits or other special, indirect and consequential
 *	damages, even if Silicon Graphics has been advised of the
 *	possibility of such damages.
 */

#include <stdio.h>
#include <nlist.h>

struct nlist nl[] = {
	{ "avenrun" },
	{ "" },
};

main()
{
	int kmem, i;
	long avenrun[3];

	if ((kmem = open("/dev/kmem", 0)) < 0) {
		perror("/dev/kmem");
		exit(1);
	}
	if (nlist("/unix", nl) < 0) {
		fprintf(stderr, "bad namelist\n");
		exit(1);
	}
	if (nl[0].n_type == 0) {
		fprintf(stderr, "can't find avenrun\n");
		exit(1);
        }
	if (lseek(kmem, (long)nl[0].n_value & 0x7fffffff, 0) < 0) {
		perror("lseek");
		exit(1);
	}
	(void) read(kmem, (char *) avenrun, sizeof(avenrun));

	printf("load average:");
	for (i = 0; i < (sizeof(avenrun)/sizeof(avenrun[0])); i++) {
		if (i > 0)
			printf(",");
		printf(" %.2f", ((double) avenrun[i])/1024.0);
	}
	printf("\n");
	exit(0);
}



More information about the Comp.sys.sgi mailing list