getrusage() in C++ Help Please!
Hey guys, I am trying to write a program to give me back the amount of time used by the processor, the starting time of the process, end time of the process, and the total elapsed time of the process. I was told that the easiest way to do it is via the getrusage() function... It's just that I have no clue how to do it. Here is what I've written so far. I need each process to print out all of those for the random numbers given as arguments.
#include <iostream.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <unistd.h>
#include <stdio.h>
int main (int argc, const char * argv[])
{
int pid, NumParent, NumChild, index = 1, x = 0;
int resourcesUsed, who;
struct rusage usage;
NumParent = atoi(argv[index]);
index++;
NumChild = atoi(argv[index]);
srand(time(NULL));
pid = fork();
if (pid == 0)
{
who = RUSAGE_CHILDREN;
for(x = 0; x < NumChild; x++)
{
cout<<"I am the Child. ";
cout<<"Random Number: " << rand();
cout<<endl;
}
}
else
{
for(x = 0; x < NumParent; x++)
{
cout<<"I am the Parent. ";
cout<<"Random Number: " << rand();
cout<<endl;
}
}
return 0;
}
Any help would be greatly appreciated. Thanks!!
-AquamaN
|