0nism

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Linux下高精度时间

time.h提供了精确到秒级的时间

		#include <time.h>
		time_t time(time_t *tloc);

为了获取更高精度,我了解了一下timespec结构体

一、struct timespec定义

		struct timespec {
				time_t tv_sec; // seconds 
				long tv_nsec; // and nanoseconds 
		};
		
		#include<time.h>
		
		 int nanosleep(const struct timespec *req, struct timespec *rem);

nanosleep() suspends the execution of the calling thread until either at least the time specified in *req has elapsed, or the delivery of a signal that triggers the invocation of a handler in the calling thread or that terminates the process.

nanosleep()函数挂起呼叫线程知道req指定的时间消逝,或者一个触发句柄请求信号的传送,在呼叫线程或者终止进程。

posted on 2018-09-28 15:46  0nism  阅读(1170)  评论(0编辑  收藏  举报