954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

'times' coding problem?

Hi,

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

#include
#include
#include

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'.

danny_froud
Newbie Poster
2 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

try this:

printf("stime %s \n",tmp.tms_stime);
printf("utime %s \n",tmp.tms_utime);

XianBin
Newbie Poster
24 posts since Aug 2004
Reputation Points: 15
Solved Threads: 0
 

or try this:
printf("stime %ld \n",tmp.tms_stime);
printf("utime %ld \n",tmp.tms_utime);

XianBin
Newbie Poster
24 posts since Aug 2004
Reputation Points: 15
Solved Threads: 0
 

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

danny_froud
Newbie Poster
2 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You