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

try this:

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.