Linux下高精度时间

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指定的时间消逝,或者一个触发句柄请求信号的传送,在呼叫线程或者终止进程。

猜你喜欢

转载自www.cnblogs.com/0nism/p/9719057.html