Skip to content

Instantly share code, notes, and snippets.

@piratejon
Created January 17, 2018 00:23
Show Gist options
  • Save piratejon/5bf86169ed2e2f1ed43710ba4aa41a3d to your computer and use it in GitHub Desktop.
Save piratejon/5bf86169ed2e2f1ed43710ba4aa41a3d to your computer and use it in GitHub Desktop.
how fast can we count?
#include <string.h>
#include <signal.h>
#include <stdio.h>
long i;
static void signal_handler ( int data ) {
printf("%ld\n", i);
}
static void install_signal_handler() {
struct sigaction sa;
memset(&sa, '\0', sizeof(sa));
sa.sa_handler = signal_handler;
sigemptyset(&(sa.sa_mask));
sa.sa_flags = SA_RESTART;
if ( sigaction(SIGUSR2, &sa, NULL) == -1 ) {
printf("unable to install signal handler\n");
} else {
printf("installed signal handler\n");
}
}
int main ( int arfc, char ** arfv ) {
install_signal_handler();
i = 0;
while ( 1 ) {
i ++;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment