Um, Jim,
times() does not offer wall time for the process. The man page to which you point is written sufficiently awkwardly that I could see how someone could read that into it.
The following program which I whipped up right quick shows that
times doesn't offer this. The program also offers a way to get wall time for a process.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h> /* note that these two have slightly different names */
#include <sys/times.h> /* note that these two have slightly different names */
int main(void)
{
long clock_ticks_per_second;
clock_t uptime;
struct timeval time1;
struct timeval time2;
struct tms times_value;
if(gettimeofday(&time1,NULL)!=0)
{
fprintf(stderr,"first gettimeofday() failed\n");
exit(1);
}
/* Put some non-compute seconds on the wall clock. */
sleep(10);
printf("=== for elapsed clock time, you do not want the following\n");
clock_ticks_per_second=sysconf(_SC_CLK_TCK);
printf("clock ticks per second=%ld\n",clock_ticks_per_second);
uptime=times(×_value);
printf("system has been running for %lu seconds\n",
uptime*clock_ticks_per_second
);
printf("user level CPU time for this process so far is %lu seconds\n",
times_value.tms_utime*clock_ticks_per_second
);
printf("kernel level CPU time for this process so far is %lu seconds\n",
times_value.tms_utime*clock_ticks_per_second
);
printf("user level CPU time for child processes so far is %lu seconds\n",
times_value.tms_utime*clock_ticks_per_second
);
printf("kernel level CPU time for child processes so far is %lu seconds\n",
times_value.tms_utime*clock_ticks_per_second
);
printf("of course, there are no child processes :)\n");
printf("=== for elapsed clock time, you want the following\n");
if(gettimeofday(&time2,NULL)!=0)
{
fprintf(stderr,"second gettimeofday() failed\n");
exit(1);
}
if(time2.tv_usec<time1.tv_usec)
{
time2.tv_usec=time2.tv_usec-time1.tv_usec+1000000;
time2.tv_sec =time2.tv_sec -time1.tv_sec -1;
}
else
{
time2.tv_usec=time2.tv_usec-time1.tv_usec;
time2.tv_sec =time2.tv_sec -time1.tv_sec;
}
printf("wall clock elapsed time is %ld.%06ld seconds\n",
time2.tv_sec,
time2.tv_usec
);
return 0;
} /* main() */
The output I got from running it was this:
Code:
=== for elapsed clock time, you do not want the following
clock ticks per second=100
system has been running for 3249928008 seconds
user level CPU time for this process so far is 0 seconds
kernel level CPU time for this process so far is 0 seconds
user level CPU time for child processes so far is 0 seconds
kernel level CPU time for child processes so far is 0 seconds
of course, there are no child processes :)
=== for elapsed clock time, you want the following
wall clock elapsed time is 10.008889 seconds
Hope this helps.