Created
November 26, 2014 18:10
-
-
Save dualbus/b392671daf5b72df4b6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <sys/time.h> | |
#include <signal.h> | |
void on_sigalrm(int sig) { | |
return; | |
} | |
int main(int argc, char *argv[]) { | |
float wait; | |
int sig; | |
sigset_t sigset; | |
struct itimerval new_value = { | |
(struct timeval){ (time_t)0, (suseconds_t)0 }, | |
(struct timeval){ (time_t)0, (suseconds_t)0 }, | |
}; | |
if(argc < 2) | |
return 1; | |
wait = strtof(argv[1], (void *)0); | |
if(wait <= 0) | |
return 1; | |
new_value.it_value.tv_sec = (time_t)wait; | |
new_value.it_value.tv_usec = (suseconds_t)((wait - (int)wait) * 1000000); | |
sigemptyset(&sigset); | |
sigaddset(&sigset, SIGALRM); | |
signal(SIGALRM, &on_sigalrm); | |
setitimer(ITIMER_REAL, &new_value, (void *)0); | |
sigwait(&sigset, &sig); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment