版權所有 © 2014 tutorialspoint
clock_t times(struct tms *buf);
struct tms { clock_t tms_utime; /* user time */ clock_t tms_stime; /* system time */ clock_t tms_cutime; /* user time of children */ clock_t tms_cstime; /* system time of children */ };
tms_utime欄位包含呼叫程序執行指令所花費的CPU時間。tms_stime欄位包含系統代表呼叫程序執行任務時所花費的CPU時間。tms_cutime欄位包含所有已等待終止子程序的tms_utime和tms_cutime值的總和。tms_cstime欄位包含所有已等待終止子程序的tms_stime和tms_cstime值的總和。
已終止子程序(及其後代)的時間在wait(2) 或waitpid(2) 返回其程序 ID 時被新增。特別是,子程序未等待的孫程序的時間永遠不會被看到。
所有報告的時間都以時鐘滴答表示。
在2.6.9之前的Linux核心版本中,如果SIGCHLD的處理方式設定為SIG_IGN,則已終止子程序的時間會自動包含在tms_cstime和tms_cutime欄位中,儘管POSIX.1-2001指出這隻有在呼叫程序wait()其子程序時才會發生。這種不符合標準的情況在Linux 2.6.9及更高版本中得到了糾正。
在Linux上,可以將buf引數指定為NULL,結果是times() 只返回函式結果。但是,POSIX沒有指定此行為,大多數其他Unix實現都需要buf的非NULL值。
請注意,clock(3) 返回的clock_t型別的值不是以時鐘滴答為單位測量的,而是以CLOCKS_PER_SEC為單位測量的。
在較舊的系統上,每秒的時鐘滴答數由變數HZ給出。
time (1)
getrusage (2)
wait (2)
廣告