Skip to content

Instantly share code, notes, and snippets.

@jstaursky
Last active June 26, 2019 03:04
Show Gist options
  • Save jstaursky/b15052dede94802aabff55cc815f58d7 to your computer and use it in GitHub Desktop.
Save jstaursky/b15052dede94802aabff55cc815f58d7 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h> // void exit( int exit_code)
#include <signal.h> // void (*signal( int sig, void (*handler) (int))) (int)
// handler must be of the form "void func (int sig)"
// signal_code is useful in-cases where handler is used for more than one signal
void handler (int signal_code)
{
printf ("\nHello World!\n");
printf ("signal value: %d\n", signal_code);
exit (1);
}
int main (int argc, char *argv[])
{
// register handler function to handle signal SIGINT = interrupt from
// keyboard (^C)
signal (SIGINT, handler);
while (1)
; // Busy Wait until application receives SIGINT.
// Never reached.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment