getrusage()

Hi,
Can someone gives me an example for the use of getrusage() under HP-UX and AIX. I am using this function to get system statistics.
Thank you

#include <stdlib.h>
#include <sys/resource.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>     


void process(struct rusage *p, char *when)
{
	printf("%s\n", when);
	printf(" /* user time used */                   %8d  %8d\n",  p->ru_utime.tv_sec,p->ru_utime.tv_usec   );
	printf(" /* system time used */                 %8d  %8d\n",  p->ru_stime.tv_sec,p->ru_stime.tv_usec   );
	printf(" /* integral shared memory size */      %8d\n",  p->ru_ixrss           );
	printf(" /* integral unshared data  */          %8d\n",  p->ru_idrss           );
	printf(" /* integral unshared stack  */         %8d\n",  p->ru_isrss           );
	printf(" /* page reclaims */                    %8d\n",  p->ru_minflt          );
	printf(" /* page faults */                      %8d\n",  p->ru_majflt          );
	printf(" /* swaps */                            %8d\n",  p->ru_nswap           );
	printf(" /* block input operations */           %8d\n",  p->ru_inblock         );
	printf(" /* block output operations */          %8d\n",  p->ru_oublock         );
	printf(" /* # of characters read/written */     %8d\n",  p->ru_ioch            );
	printf(" /* messages sent */                    %8d\n",  p->ru_msgsnd          );
	printf(" /* messages received */                %8d\n",  p->ru_msgrcv          );
	printf(" /* signals received */                 %8d\n",  p->ru_nsignals        );
	printf(" /* voluntary context switches */       %8d\n",  p->ru_nvcsw           );
	printf(" /* involuntary  */                     %8d\n",  p->ru_nivcsw          );

}


int main()
{
	  int ret;
	  char *buf;
	  int i=0;
	  int who= RUSAGE_SELF;
	  struct rusage usage;
	  struct rusage *p=&usage;

	  ret=getrusage(who,p);
	  process(p, "-------------before");
	  /* do stuff here */
      ret=getrusage(who,p);
	  process(p, "\n\n-------------after we run foo1");    

	return 0;
}

Note getrusage() works only for a process and its children.

Thank you
I tested this code but I can't understand why the user time and the system time are the same before and after execution.

-------------before
/* user time used / 0 10000
/
system time used / 0 10000
/
integral shared memory size / 0
/
integral unshared data / 0
/
integral unshared stack / 0
/
page reclaims / 149
/
page faults / 1
/
swaps / 0
/
block input operations / 0
/
block output operations / 0
/
# of characters read/written / 1676
/
messages sent / 0
/
messages received / 0
/
signals received / 0
/
voluntary context switches / 1
/
involuntary */ 14

-------------after we run foo1
/* user time used / 0 10000
/
system time used / 0 10000
/
integral shared memory size / 0
/
integral unshared data / 0
/
integral unshared stack / 0
/
page reclaims / 149
/
page faults / 2
/
swaps / 0
/
block input operations / 0
/
block output operations / 0
/
# of characters read/written / 2500
/
messages sent / 0
/
messages received / 0
/
signals received / 0
/
voluntary context switches / 2
/
involuntary */ 14

Normally I must calculate the difference between the two statistics to obtain statistics of my program execution. So I will obtain 0 for the user time and system time ???