what is going on here ???

ab at unido.UUCP ab at unido.UUCP
Fri May 31 03:30:00 AEST 1985


If you are running 4.2, look at the following short program and
guess what it will do. Then compile and run it and find out
what it really does. 

Try to explain its behavior!! (- Is it a bug in 4.2 ??? :-) )

	Andreas

--
Andreas Bormann                 ab at unido.UUCP
University of Dortmund          N 51 29' 05"   E 07 24' 42"
West Germany

--- CUT HERE ---------- CUT HERE ---------- CUT HERE ---------- CUT HERE ----
#include <nlist.h>

#define NAMELIST "/vmunix"

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

main()
{
	register int    kmem;
	double  avg[3];

	if((kmem = open ("/dev/kmem", 0) < 0)) {
		printf("Cannot open kmem\n");
		exit(1);
	}
	nlist(NAMELIST, avenrun);
	if(avenrun[0].n_type == 0) {
		printf("Cannot find avenrun\n");
		exit(1);
	}
	lseek(kmem, (long) avenrun[0].n_value, 0);
	read(kmem, (char *) avg, 3 * sizeof (double));
	printf("Load average: %f %f %f\n", avg[0], avg[1], avg[2]);
	exit(0);
}



More information about the Comp.unix mailing list