Subject: getrusage() does not report ru_maxrss (does it?) back as far as 1.6_BETA2 and on -current.
To: None <current-users@netbsd.org>
From: Marc Tooley <netbsdMLpostNO@spam.quake.ca>
List: current-users
Date: 12/06/2005 17:31:15
Am I missing something?

Is getrusage() really supposed to return essentially no useful 
information? Is there no platform-independent way to measure how much 
memory the current process is eating up? I noticed this after turning 
on process accounting and realising that all entries from:

sa -u

... were all "0k mem" right up and down the line.

Comments much appreciated.

#include <sys/resource.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>

int main() {
	int b,c;
	struct rusage mine;
	char buf[1024];
	char *buf2;

	printf("%d bytes for buffer size..\n", sizeof(buf));
	for (c=0; c<100; c++) {
		buf2=(char *)malloc(1000000);
		if (!buf2) {
			printf("Error: unable to alloc 1,000,000\n");
			exit(-1);
		} else {
			printf("Allocated 1,000,000 bytes.\n");
			for (b=0; b<100000; b++) {
				buf2[b]=(char)b;
			}
		}
	}
	printf("Sleeping for 10..\n");
	sleep(10);
	b=getrusage(RUSAGE_SELF, &mine);
	if (b==-1) {
		perror("Error from getrusage()");
		exit(-1);
	} else {
		printf("maxrss: %ld\n", mine.ru_maxrss);
	}
}

[blahblah]
maxrss: 0

--
P.S. Please respond to the Reply-To: header and send your note back to 
the list. Thank you.