signals

Multiple alarms in C?

风流意气都作罢 提交于 2020-11-29 23:53:04
问题 This is probably a very basic question, but I'm using the code below to run a simple alarm. It works as I want it to, but I'm wondering if it's at all possible to run multiple alarms simultaneously that each trigger a different function when complete. Is there a way to do that? #include <signal.h> #include <sys/time.h> #include <stdio.h> #include <time.h> void alarm_handler(int signum){ printf("five seconds passed!!\n"); } int main(){ signal(SIGALRM, alarm_handler); alarm(5); pause(); return

Multiple alarms in C?

吃可爱长大的小学妹 提交于 2020-11-29 23:53:03
问题 This is probably a very basic question, but I'm using the code below to run a simple alarm. It works as I want it to, but I'm wondering if it's at all possible to run multiple alarms simultaneously that each trigger a different function when complete. Is there a way to do that? #include <signal.h> #include <sys/time.h> #include <stdio.h> #include <time.h> void alarm_handler(int signum){ printf("five seconds passed!!\n"); } int main(){ signal(SIGALRM, alarm_handler); alarm(5); pause(); return

C/C++: How to exit sleep() when an interrupt arrives?

和自甴很熟 提交于 2020-11-25 03:33:17
问题 I'm looking for a way to exit sleep when an user interrupt arrives - its important to exit sleep rather than do this: interrupt sleep , do ISR processing, and go back to sleep - which is what I'm finding solutions for. I'm looking for something like this in C++ - an equivalent in C is even better: void * timer_thread(void*dummy) { while(1) { // Check if some callbacks are to be given // when all are given, Determine x duration to sleep try { sleep(x); } except(/* the except block should hit

C/C++: How to exit sleep() when an interrupt arrives?

你说的曾经没有我的故事 提交于 2020-11-25 03:29:31
问题 I'm looking for a way to exit sleep when an user interrupt arrives - its important to exit sleep rather than do this: interrupt sleep , do ISR processing, and go back to sleep - which is what I'm finding solutions for. I'm looking for something like this in C++ - an equivalent in C is even better: void * timer_thread(void*dummy) { while(1) { // Check if some callbacks are to be given // when all are given, Determine x duration to sleep try { sleep(x); } except(/* the except block should hit