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

分类:

技术点:

相关文章:

  • 2021-10-19
  • 2021-08-11
  • 2021-08-12
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案