I am checking process duration with C code. It works in Windows 32 bits environment, but not in Linux 64bits.
At least my process takes longer than 3 minutes, but it shows 0.062 sec. My code is below.
#include <stdio.h>
#include <time.h>
#include <Windows.h>
int main(void)
{
clock_t start = clock();
//....... doing something. Sorry:D
printf("%.3f sec\n", (double)(clock() - start) / CLOCKS_PER_SEC);
return 0;
}
How to fixed this code to work in 64bits Linux also? Thanks.
The function
clock(3)
doesn't yield the elapsed time:As the simplest example, if your process sleeps or block for I/O, it won't use much CPU time. If you need to measure actual duration, you could use
time(3)
anddifftime(3)
or maybeclock_gettime
and the like.Side note: I don't really understand why the code appears to work in Windows, but changing to
time
+difftime
should work on both platforms.