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指定的時間消逝,或者一個觸發句柄請求信號的傳送,在呼叫線程或者終止進程。
