Last active
January 5, 2017 16:03
-
-
Save SkypLabs/f7e16134a43b21202645e3bddfd66538 to your computer and use it in GitHub Desktop.
Example of how to manipulate UNIX signals in C
This file contains 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 <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