LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-22-2003, 12:23 AM   #1
AquamaN
Member
 
Registered: Oct 2002
Location: Ohio, USA
Distribution: OS X 10.4.8, Ubuntu 6.10
Posts: 146

Rep: Reputation: 15
Exclamation 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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration