Home:ALL Converter>Linux periodic C timers without using signal callback

Linux periodic C timers without using signal callback

Ask Time:2021-09-22T05:46:08         Author:Jimmy

Json Formatter

Requirement is simple - Implement a C periodic timer, which can fire every say x seconds and a timer callback function should be called everytime that timer expires. Seems a simple enough question and I have browsed the web, but I am finding examples which either have FD and poll involved, or the timer callback is implemented using SIGNAL handler. I want to avoid both. Can you please share some code examples

https://man7.org/linux/man-pages/man2/timer_create.2.html - uses signals, which is not of interest to me as in my processes, there may be other reasons this SIGNAL can be called , how can I differentiate in the SIG-handler, that this signal is for my timer and not other events ?

Author:Jimmy,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275886/linux-periodic-c-timers-without-using-signal-callback