在到达指定的日期/时间时,是否可以在Linux的C/C ++中得到通知? [英] Is it possible in C/C++ in Linux to get informed when a specified date/time is reached?
问题描述
在Linux上使用标准C ++是否有可能在系统时间到达指定的日期/时间时得到通知(假设我的过程已经完成)?
Is it possible using standard C++ in Linux to get informed when a specified date/time is reached by the system time (assuming my process is up of course)?
我可以将计时器设置为需要等待的时间,但是如果用户更改系统时间会怎样?系统能否通知我用户更改了系统时间来重置我的计时器?
I could just set a timer to the time I need to wait, but what happens if the user changes the system time? Can I get informed by the system that the user changed the system time to reset my timers?
推荐答案
Linux内核具有此类系统调用,尽管它们未集成到libc API中.您可以创建一个计时器,从内核获取它的文件描述符,然后对描述符进行选择或epoll调用,以在计时器触发时得到通知.
The Linux kernel has such system calls, although, they are not integrated into the libc API. You can create a timer, get a file descriptor for it from the kernel, and do a select or epoll call on the descriptor to be notified when the timer fires.
手册页: http://www.kernel.org/doc/man-pages/online/pages/man2/timerfd_create.2.html
这篇关于在到达指定的日期/时间时,是否可以在Linux的C/C ++中得到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!