I need a timer to execute callbacks with relatively low resolution. What\'s the best way to implement such C++ timer class in Linux? Are there any libraries I could use?
Try the clock_gettime() function, defined in time.h:
int clock_gettime(clockid_t clk_id, struct timespec *tp); struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ };
Typically you might call it like this:
struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts);