'times' coding problem?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 2
Reputation: danny_froud is an unknown quantity at this point 
Solved Threads: 0
danny_froud danny_froud is offline Offline
Newbie Poster

'times' coding problem?

 
0
  #1
Sep 9th, 2004
Hi,

I confess I am stuck. Can anyone see a problem with the following code, to be run under Linux, compiled with g++ ?

#include <stdio.h>
#include <sys/types.h>
#include <sys/times.h>

int main () {
struct tms tmp;

times(&tmp);
printf("stime %d \n",tmp.tms_stime);
printf("utime %d \n",tmp.tms_utime);

return(0);
}


The code compiles and runs no problem.
I was expecting an output of a couple of large numbers that changed with time. Instead all I get it '0' and '1'.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 24
Reputation: XianBin is an unknown quantity at this point 
Solved Threads: 0
XianBin XianBin is offline Offline
Newbie Poster

Re: 'times' coding problem?

 
0
  #2
Sep 9th, 2004
try this:

printf("stime %s \n",tmp.tms_stime);
printf("utime %s \n",tmp.tms_utime);
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 24
Reputation: XianBin is an unknown quantity at this point 
Solved Threads: 0
XianBin XianBin is offline Offline
Newbie Poster

Re: 'times' coding problem?

 
0
  #3
Sep 9th, 2004
or try this:
printf("stime %ld \n",tmp.tms_stime);
printf("utime %ld \n",tmp.tms_utime);
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 2
Reputation: danny_froud is an unknown quantity at this point 
Solved Threads: 0
danny_froud danny_froud is offline Offline
Newbie Poster

Re: 'times' coding problem?

 
0
  #4
Sep 14th, 2004
Thanks for your help, XianBin,

I discovered that using tms.millitm provides the information that I need. I don't know why it didn't like utime or stime, but I'll check that some other time.

Thanks again,
Danny
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC