欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > Android C++系列:Linux常用函数和工具

Android C++系列:Linux常用函数和工具

2024/10/25 7:32:44 来源:https://blog.csdn.net/sjw890821sjw/article/details/140267988  浏览:    关键词:Android C++系列:Linux常用函数和工具

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com