2
我使用times()函數來測量值,但我不確定我的方法是否正確。請看看和建議測量時間由一個exec() - 在Linux上的編輯過程
struct tms tms_start, tms_end;
if (!(pid=fork()))
{
//some necessary operations here
times(&tms_start);
execl(...);
}
else if (pid)
{
//in parent
int status;
wait(&status);
times(&tms_end);
if (WIFEXITED(status))
{
if(WEXITSTATUS(status)==0)
{
clock_t real = tms_end.tms_cstime - tms_start.tms_stime
float running_time = real/(double)sysconf(_SC_CLK_TK);
}
}
}
啊我明白了。所以這個差異計算是正確的,我猜? clock_t real = tms_end.tms_cstime - tms_start.tms_stime – user108127 2009-07-02 20:09:04