Skip to content

Instantly share code, notes, and snippets.

@SkypLabs
Last active January 5, 2017 16:03
Show Gist options
  • Save SkypLabs/f7e16134a43b21202645e3bddfd66538 to your computer and use it in GitHub Desktop.
Save SkypLabs/f7e16134a43b21202645e3bddfd66538 to your computer and use it in GitHub Desktop.
Example of how to manipulate UNIX signals in C
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#define SIGTERM 15
#define SIGKILL 9
#define SIGINT 2
void signal_handler(int signal)
{
printf("Caugth signal %d\t", signal);
if (signal == SIGTERM)
printf("SIGTERM\n");
else if (signal == SIGKILL)
printf("SIGKILL\n");
else if (signal == SIGINT)
printf("SIGINT\n");
}
int main ()
{
signal(SIGTERM, signal_handler);
signal(SIGKILL, signal_handler);
signal(SIGINT, signal_handler);
while (1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment