Reputation: 2882
Greetings,
I was wondering if there is a way to use a timer in combination with linux poll/epoll API. I already use epoll and it would integrate very nice with the existing code if i could make the timer to be just another epoll event in my queue.
A possible way is maybe, a file-based Timer, like
echo 400;now > /dev/timer ; cat /dev/timer ; # outputs after 400ms "now"
just as an imaginary example. Is there something like this? Or are there other ways i could integrate it with the epoll API?
--Marenz
Upvotes: 2
Views: 3760
Reputation: 63616
It is trivial to do timers with epoll, because epoll_wait also takes a timeout parameter; you simply put all your timers into a priority queue and set timeout to the time between now and the first one, then fire the events for that timer.
Or use use libevent which provides something similar.
Yes you COULD use timerfd() if you really wanted, but there's no need.
Upvotes: 8
Reputation: 3606
Would the watch -n 0.4
command be any use in this situation?
Upvotes: 0