简体   繁体   中英

epoll_wait and changing system time back

My app uses epoll_wait to perform a timed wait for IO events. If no event happens, epoll_wait is supposed to return after the timeout and my app continues.

During testing, someone turn the system clock back by a day and the part of my app that uses epoll_wait stopped working for 24 hours. Obviously, this is a problem.

I've rummaged around looking for something that might allow my app to know that the time has changed (for example, a signal) but I haven't found anything.

Is there any way to deal with abrupt time changes like this?

使用基于单调时间的计时器(例如timer_create(2))来生成信号并执行阻塞epoll_wait,并检查-1返回码和errno是否设置为EINTR。

The Linux kernel implementation of epoll_wait uses CLOCK_MONOTONIC so it should be immune to system clock changes. (I investigated this since I was seeing a similar problem and wanted to discount epoll_wait as a possible cause.) Before v2.6.37 it used to use jiffies which are also monotonic.

I've submitted a patch to the epoll_wait man page to clarify this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM