Skip to content

Instantly share code, notes, and snippets.

@phire
Created March 16, 2021 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phire/726ee1f48ef8e2e5e4f0a8c9e4069489 to your computer and use it in GitHub Desktop.
Save phire/726ee1f48ef8e2e5e4f0a8c9e4069489 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdatomic.h>
#include <stdlib.h>
atomic_int count = 0;
void sig_handler(int signum) {
printf("Alarm %i\n", count++);
if (count == 3) {
exit(0);
}
alarm(1);
}
int main() {
signal(SIGALRM,sig_handler);
alarm(1);
for(;;) {
sleep(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment