[comp.sys.sgi] How to get avenrun

amoss@shum.UUCP (Amos Shapira) (11/22/90)

Hello,
 I need to write a program which will get the load avarage (to port
 a batch system).

 I call nlist(3) and get the right offset (compared to nm(1) output)
 but when trying to lseek(2) to the place I get an "Invalid argument"
 error (and no seek is done).

 According to the manual, the problem is that lseek will not allow
 a negative result on file descriptors which are not "remote file
 descriptors" (what is it?). (lseek(2), Version 4.0, July 1989).

 The file descriptor, which could be a cause for the same kind
 of error code, is O.K., since the read(2) I do doesn't complain
 about it.

 My system is an Iris 4D/240GTX running Irix 3.3.1.

 Please reply by e-mail (or at least send a copy of the reply) to
 amoss@batata.huji.ac.il.

Thanks in advance,
Amos Shapira
amoss@batata.huji.ac.il

jmb@patton.wpd.sgi.com (Doctor Software) (11/29/90)

In article <amoss.659280210@shum>, amoss@shum.UUCP (Amos Shapira) writes:
>  I need to write a program which will get the load avarage (to port
>  a batch system).

The easiest way to do this is to use the sysmp(2) call. Peruse the
header file /usr/include/sys/sysmp.h, which gives the different commands
you can give as well. For instance, to get the kernel address of the
avenrun array:

	avenrunp = sysmp(MP_KERNADDR, MPKA_AVENRUN);
	avenrunp &= ~0x8000000;

This value can then be passed directly to lseek(2) on /dev/kmem, and you
can then read out the array.

Another possibility is to use the same sequence above to get the address
of avenrun, but instead of seeking and reading on /dev/kmem, just use
the mmap(2) system call to map the kernel into your address space. Then
you can read avenrun directly without any system call overhead.

-- Jim Barton
   Silicon Graphics Computer Systems
   jmb@sgi.com