草庐IT

c - Linux,timerfd精度

我的系统需要至少10毫秒的计时器精度。我选择了timerfd,因为它非常适合我,但发现即使是长达15毫秒的时间,它也根本不准确,或者我不明白它是如何工作的。我在10毫秒计时器上测量的时间高达21毫秒。我整理了一个快速测试来显示我的问题。这是一个测试:#include#include#include#include#include#include#include#includeintmain(intargc,char*argv[]){inttimerfd=timerfd_create(CLOCK_MONOTONIC,0);intmilliseconds=atoi(argv[1]);str

c - Linux,timerfd精度

我的系统需要至少10毫秒的计时器精度。我选择了timerfd,因为它非常适合我,但发现即使是长达15毫秒的时间,它也根本不准确,或者我不明白它是如何工作的。我在10毫秒计时器上测量的时间高达21毫秒。我整理了一个快速测试来显示我的问题。这是一个测试:#include#include#include#include#include#include#include#includeintmain(intargc,char*argv[]){inttimerfd=timerfd_create(CLOCK_MONOTONIC,0);intmilliseconds=atoi(argv[1]);str

c - Linux timerfd> 每 x 秒调用一个函数而不阻塞代码执行

需要每X(比如说5)秒调用一个函数,下面的代码就是这样做的。但是它阻塞了代码的执行。因为我希望它像setitimer()一样工作,我可以(例如)每5秒调用一个函数并执行其他操作。#include#include#include#include#include#include/*Definitionofuint64_t*/#definehandle_error(msg)\do{perror(msg);exit(EXIT_FAILURE);}while(0)intmain(intargc,char*argv[]){structitimerspecnew_value;intmax_exp,f

linux - epoll 与 timerfd

我想用newValue的it_interval来设置超时的时间间隔。但在我的示例中,我只能打印timeout一次。发生了什么?如何设置间隔?这是我的代码:intmain(){intefd=epoll_create(256);setnonblock(efd);structepoll_eventev,events[256];inttfd;//timerfdif((tfd=timerfd_create(CLOCK_MONOTONIC,TFD_NONBLOCK))0){//justicefor(inti=0;i 最佳答案 这是因为您正在使用