【发布时间】:2009-07-02 19:56:17
【问题描述】:
我正在使用 times() 函数来测量值,但我不确定我的方法是否正确。请看看和建议
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);
}
}
}
【问题讨论】: