Created
January 17, 2018 00:23
-
-
Save piratejon/5bf86169ed2e2f1ed43710ba4aa41a3d to your computer and use it in GitHub Desktop.
how fast can we count?
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 <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