网站建设如何跑单子,西安制作网站软件,东营招聘信息网官网,大鹏新区网站建设精度
clock_settime()精度比settimeofday()高#xff0c;受限制于参数的结构体#xff0c;一个是ns级精度#xff0c;另一个us级精度。具体两个函数原因参考如下。 int clock_settime(clockid_t clk_id, const struct timespec *tp); int settimeofday(const struct timeva…精度
clock_settime()精度比settimeofday()高受限制于参数的结构体一个是ns级精度另一个us级精度。具体两个函数原因参考如下。 int clock_settime(clockid_t clk_id, const struct timespec *tp); int settimeofday(const struct timeval *tv, const struct timezone *tz);
struct timespec {time_t tv_sec; /* seconds */long tv_nsec; /* nanoseconds */
};struct timeval {time_t tv_sec; /* seconds */suseconds_t tv_usec; /* microseconds */
};着重介绍更好精度的clock_settime()、clock_gettime()函数。
头文件、函数和原型
#include time.h
int clock_getres(clockid_t clk_id, struct timespec *res);
int clock_gettime(clockid_t clk_id, struct timespec *tp);
int clock_settime(clockid_t clk_id, const struct timespec *tp);struct timespec {time_t tv_sec; /* seconds */long tv_nsec; /* nanoseconds */
};介绍
函数clock_getres()寻找指定时钟clk_id的分辨率如果res不未空将通过res把clk_id的分辨率存入到结构体指针timespec内。时钟分辨率取决于实施和通过特定进程不可配置。如果 clock_settime()的参数 tp 指向的时间值不是 res 的倍数则它将被截断为 res 的倍数。
函数clock_getttime()和clock_settime() 取回和设置指定时钟clk_id的时间。
其中clk_id参数是识别指定时钟并行动。时钟是系统范围且所有程序可见或者单独成预处理测试时间。
CLOCK_REALTIME所有执行支持系统范围的real-time时钟从特定时代开始的代表的秒和纳秒。当时间开始改变相关间隔定时器将不启作用但是定时器的绝对点是起作用的。
时钟
CLOCK_REALTIME: 系统范围时钟测量一个实时时间(wall-clock).设置实时时钟需要合适的权限。实时时钟由于系统不连续跳跃所影响(例如如果系统管理员经常修改实时时钟)和通过adjtime()增量调整和NTP。
CLOCK_MONITONIC: 时钟不能够被设置和正如POSIX所描述的单调时间–“过去一些未指定点”。在 Linux 上该点对应于系统自启动以来运行的秒数。
返回值
返回值结论0成功-1失败