1. 時間函數
1.1 文件訪問時間
#include <sys/types.h>
#include <utime.h>
int utime (const char *name, const struct utimebuf *t);
返回:若成功則為 0,若出錯則為- 1
如果times是一個空指針,則存取時間和修改時間兩者都設置為當前時間;
如果times是非空指針,則存取時間和修改時間被設置為 times所指向的結構中的值。此 時,進程的有效用戶ID必須等于該文件的所有者 ID,或者進程必須是一個超級用戶進程。對 文件只具有寫許可權是不夠的
此函數所使用的結構是:
struct utimbuf {
time_t actime; /*access time*/
time_t modtime; /*modification time*/ }
1.2 cpu使用時間
#include <sys/time.h>
#include <sys/resource.h>
int getrusage(int who, struct rusage *usage);
-
RUSAGE_SELF:Return resource usage statistics for the calling process, which is the sum of resources used by all threads in the process.
-
RUSAGE_CHILDREN:Return resource usage statistics for all children of the calling process that have terminated and been wait