时间函数

18.1 文件访问时间

如果times是一个空指针,则存取时间和修改时间两者都设置为当前时间;

如果times是非空指针,则存取时间和修改时间被设置为 times所指向的结构中的值。此 时,进程的有效用户ID必须等于该文件的所有者 ID,或者进程必须是一个超级用户进程。对 文件只具有写许可权是不够的

此函数所使用的结构是:

18.2 cpu使用时间

#include <sys/types.h>
#include <utime.h>
int utime (const char *name, const struct utimebuf *t); 返回:若成功则为 0,若出错则为- 1

struct utimbuf {
time_t actime; /*access time*/ time_t modtime; /*modification time*/ }

#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.

218 第18章 时间函数

RUSAGE_CHILDREN
Return resource usage statistics for all children of the calling process that have terminated and been waited for. These statis‐ tics will include the resources used by grandchildren, and fur‐ ther removed descendants, if all of the intervening descendants waited on their terminated children.

RUSAGE_THREAD (since Linux 2.6.26)
Return resource usage statistics for the calling thread.

猜你喜欢

转载自blog.csdn.net/lanlan1266/article/details/80165957