LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-17-2003, 03:31 PM   #1
cxel91a
Member
 
Registered: May 2001
Posts: 61

Rep: Reputation: 15
Accessing a struct inside struct


How can I call the ru_stime and ru_ctime members. Since the both belong to struct timeval inside struct rusage.

#include<iostream>
using namespace std;
#include<unistd.h>
#include<sys/resource.h>
#include<errno.h>
#include<sys/time.h>

int main()
{
struct rusage* resource= new struct rusage;

if( getrusage(RUSAGE_SELF, resource) == -1 ){
perror("getrusage error");
exit(1);
}

cout<<"The ru_stime is "<<resource->timeval.ru_stime<<endl;
cout<<"The ru_utime is "<<resource->timeval.ru_utime<<endl;
cout<<endl;

return 0;
}
 
Old 09-17-2003, 04:24 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You needed to sepcify the member of struct timeval. They are tv_sec and tv_usec.

Code:
#include <stdio.h>
#include<iostream>
#include<unistd.h>
#include<sys/resource.h>
#include<errno.h>
#include<sys/time.h>

using namespace std;

int main()
{
   struct rusage resource;

   if( getrusage(RUSAGE_SELF, &resource) == -1 )
   {
      perror("getrusage error");
      exit(1);
   }

   cout << "The ru_stime.tv_sec is "<< resource.ru_stime.tv_sec <<endl;
   cout << "The ru_stime.tv_usec is "<< resource.ru_stime.tv_usec <<endl;
   cout << "The ru_utime.tv_sec is "<< resource.ru_utime.tv_sec <<endl;
   cout << "The ru_utime.tv_usec is "<< resource.ru_utime.tv_usec <<endl;
   cout << endl;

   return 0;
}
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
seg. fault when allocating memory via a pointer inside a struct elmafiacs Programming 4 02-20-2005 07:26 AM
g++ and wrong struct member addresses / struct size misreporting sonajiso Linux - General 5 05-22-2004 10:16 PM
Push into Vectors inside struct in C++ !! Hady Programming 6 05-14-2004 08:34 AM
switch statement converting struct char to struct int oceaneyes2 Programming 2 12-10-2003 04:30 PM
using struct type X as pointer in struct X. worldmagic Programming 1 10-28-2003 02:06 PM

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

All times are GMT -5. The time now is 05:09 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