943,405 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2788
  • C RSS
Sep 9th, 2004
0

'times' coding problem?

Expand Post »
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'.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
danny_froud is offline Offline
2 posts
since Sep 2004
Sep 9th, 2004
0

Re: 'times' coding problem?

try this:

printf("stime %s \n",tmp.tms_stime);
printf("utime %s \n",tmp.tms_utime);
Reputation Points: 15
Solved Threads: 0
Newbie Poster
XianBin is offline Offline
24 posts
since Aug 2004
Sep 9th, 2004
0

Re: 'times' coding problem?

or try this:
printf("stime %ld \n",tmp.tms_stime);
printf("utime %ld \n",tmp.tms_utime);
Reputation Points: 15
Solved Threads: 0
Newbie Poster
XianBin is offline Offline
24 posts
since Aug 2004
Sep 14th, 2004
0

Re: 'times' coding problem?

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
danny_froud is offline Offline
2 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC