getrusage call and results...
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > getrusage call and results...




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    getrusage call and results...  
Solomon_Man


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-19-07 06:17 PM

All,
I am working on a graduate project that I am scratching my head at one
of the results I am getting and I am not sure why.....Here is some
code....


pid = fork();
if (pid == 0) /* child */
{   //Do some work Mathematical work
.........
//Print 1
error = getrusage(RUSAGE_SELF,&TimeVal); //Get Usage Info
cout<<"User:"<<TimeVal.ru_utime.tv_sec<<"
"<<TimeVal.ru_utime.tv_usec<<endl;
cout<<"Sys:"<<TimeVal.ru_stime.tv_sec<<"
"<<TimeVal.ru_stime.tv_usec<<endl;
cout<<"Child Process Exitting "<<endl;
exit(0); //End Child Process
}
else     /* parent */
{
signal (SIGCHLD, parentProcessSignalCatcher);
while (1){
}
}

void parentProcessSignalCatcher(int x)
{
struct rusage TimeVal;
int error = 0;
...
//Print 2
error = getrusage(RUSAGE_SELF,&TimeVal); //Get Parent Usage Info
cout<<"PUser:"<<TimeVal.ru_utime.tv_sec<<"
"<<TimeVal.ru_utime.tv_usec<<endl;
cout<<"PSys:"<<TimeVal.ru_stime.tv_sec<<"
"<<TimeVal.ru_stime.tv_usec<<endl;
//Print 3
error = getrusage(RUSAGE_CHILDREN,&TimeVal); //Get Children Usage
Info
cout<<"CUser:"<<TimeVal.ru_utime.tv_sec<<"
"<<TimeVal.ru_utime.tv_usec<<endl;
cout<<"CSys:"<<TimeVal.ru_stime.tv_sec<<"
"<<TimeVal.ru_stime.tv_usec<<endl;
exit(0);
}


So I get results that seem reasonable for the child output (Print 1)
and I get values that are reasonable for the parent section Parent
values (Print 2) but for the parent section for child usage (Print 3)
I get zeros. I am not sure on why.

Any one have any ideas?

Thanks in advance,
Chris






[ Post a follow-up to this message ]



    Re: getrusage call and results...  
Solomon_Man


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-07 12:15 AM

On Feb 19, 1:31 pm, "Solomon_Man" <cmgra...@gmail.com> wrote:
> All,
> I am working on a graduate project that I am scratching my head at one
> of the results I am getting and I am not sure why.....Here is some
> code....
>
> pid = fork();
>  if (pid == 0) /* child */
>   {   //Do some work Mathematical work
> .........
>     //Print 1
>     error = getrusage(RUSAGE_SELF,&TimeVal); //Get Usage Info
>     cout<<"User:"<<TimeVal.ru_utime.tv_sec<<"
> "<<TimeVal.ru_utime.tv_usec<<endl;
>     cout<<"Sys:"<<TimeVal.ru_stime.tv_sec<<"
> "<<TimeVal.ru_stime.tv_usec<<endl;
>     cout<<"Child Process Exitting "<<endl;
>     exit(0); //End Child Process
>  }
>   else     /* parent */
>     {
>        signal (SIGCHLD, parentProcessSignalCatcher);
>         while (1){
>         }
>    }
>
> void parentProcessSignalCatcher(int x)
> {
>     struct rusage TimeVal;
>     int error = 0;
>      ....
>     //Print 2
>     error = getrusage(RUSAGE_SELF,&TimeVal); //Get Parent Usage Info
>     cout<<"PUser:"<<TimeVal.ru_utime.tv_sec<<"
> "<<TimeVal.ru_utime.tv_usec<<endl;
>     cout<<"PSys:"<<TimeVal.ru_stime.tv_sec<<"
> "<<TimeVal.ru_stime.tv_usec<<endl;
>     //Print 3
>     error = getrusage(RUSAGE_CHILDREN,&TimeVal); //Get Children Usage
> Info
>     cout<<"CUser:"<<TimeVal.ru_utime.tv_sec<<"
> "<<TimeVal.ru_utime.tv_usec<<endl;
>     cout<<"CSys:"<<TimeVal.ru_stime.tv_sec<<"
> "<<TimeVal.ru_stime.tv_usec<<endl;
>     exit(0);
>
> }
>
> So I get results that seem reasonable for the child output (Print 1)
> and I get values that are reasonable for the parent section Parent
> values (Print 2) but for the parent section for child usage (Print 3)
> I get zeros. I am not sure on why.
>
> Any one have any ideas?
>
> Thanks in advance,
> Chris

Maybe I should add I would expect to see a number similar to the Print
1 Section.

Am I wrong on thinking this?

Thanks,
Chris






[ Post a follow-up to this message ]



    Re: getrusage call and results...  
Bin Chen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-07 06:26 AM

On 2=D4=C220=C8=D5, =C9=CF=CE=E73=CA=B149=B7=D6, "Solomon_Man" <cmgra...@gm=
ail.com> wrote:
> On Feb 19, 1:31 pm, "Solomon_Man" <cmgra...@gmail.com> wrote:
>
>
> 
> 
> 
> 
> 
> 
> 
>
> Maybe I should add I would expect to see a number similar to the Print
> 1 Section.
>
> Am I wrong on thinking this?
I don't run your program but I don't know why you think its wrong.
When the SIGCHILD is fired it indicates the child is exited. This time
you get the child usage it returns zero, whats the problem?
>
> Thanks,
> Chris







[ Post a follow-up to this message ]



    Re: getrusage call and results...  
Solomon_Man


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-07 06:26 AM

On Feb 19, 8:25 pm, "Bin Chen" <binary.c...@gmail.com> wrote:
> On 2=E6=9C=8820=E6=97=A5,  =E4=B8=8A=E5=8D=883=E6=97=B649=E5=88=86,
 "Solom=
on_Man" <cmgra...@gmail.com> wrote:[vbcol=seagreen]
> 
> 
> 
> 
ge[vbcol=seagreen] 
> 
> 
> 
> 
> 
> 
>
> I don't run your program but I don't know why you think its wrong.
> When the SIGCHILD is fired it indicates the child is exited. This time
> you get the child usage it returns zero, whats the problem?
>
>
> 
All,
I was expecting the time that was originally returned from the child
process (Print 1) to match the time received in the parent process for
the child (Print 3). Am I wrong on this assumption and is it even
possible to get an exited child process usage from its parent process?

Thanks,
Chris







[ Post a follow-up to this message ]



    Re: getrusage call and results...  
Geoff Clare


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-07 06:17 PM

"Solomon_Man" <cmgray74@gmail.com> wrote, on Mon, 19 Feb 2007:

> pid = fork();
>  if (pid == 0) /* child */
>   {   //Do some work Mathematical work
> .........
>     //Print 1
>     error = getrusage(RUSAGE_SELF,&TimeVal); //Get Usage Info
>     cout<<"User:"<<TimeVal.ru_utime.tv_sec<<"
> "<<TimeVal.ru_utime.tv_usec<<endl;
>     cout<<"Sys:"<<TimeVal.ru_stime.tv_sec<<"
> "<<TimeVal.ru_stime.tv_usec<<endl;
>     cout<<"Child Process Exitting "<<endl;
>     exit(0); //End Child Process
>  }
>   else     /* parent */
>     {
>        signal (SIGCHLD, parentProcessSignalCatcher);
>         while (1){
>         }
>    }
>
> void parentProcessSignalCatcher(int x)
> {
>     struct rusage TimeVal;
>     int error = 0;
>      ....
>     //Print 2
>     error = getrusage(RUSAGE_SELF,&TimeVal); //Get Parent Usage Info
>     cout<<"PUser:"<<TimeVal.ru_utime.tv_sec<<"
> "<<TimeVal.ru_utime.tv_usec<<endl;
>     cout<<"PSys:"<<TimeVal.ru_stime.tv_sec<<"
> "<<TimeVal.ru_stime.tv_usec<<endl;
>     //Print 3
>     error = getrusage(RUSAGE_CHILDREN,&TimeVal); //Get Children Usage
> Info
>     cout<<"CUser:"<<TimeVal.ru_utime.tv_sec<<"
> "<<TimeVal.ru_utime.tv_usec<<endl;
>     cout<<"CSys:"<<TimeVal.ru_stime.tv_sec<<"
> "<<TimeVal.ru_stime.tv_usec<<endl;
>     exit(0);
> }
>
>
> So I get results that seem reasonable for the child output (Print 1)
> and I get values that are reasonable for the parent section Parent
> values (Print 2) but for the parent section for child usage (Print 3)
> I get zeros. I am not sure on why.

The parent hasn't waited for the child (unless there was a waitpid()
or equivalent call in the part of parentProcessSignalCatcher() you
didn't show).

The description of getrusage() in SUSv3 says:

"If the value of the who argument is RUSAGE_CHILDREN, information
shall be returned about resources used by the terminated and
waited-for children of the current process. If the child is never
waited for (for example, if the parent has SA_NOCLDWAIT set or
sets SIGCHLD to SIG_IGN), the resource information for the child
process is discarded and not included in the resource information
provided by getrusage()."

--
Geoff Clare <netnews@gclare.org.uk>






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:56 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register