Created
March 24, 2017 08:01
-
-
Save jsfaint/01c53d5c13f9e1d4fd3bf071d99f4375 to your computer and use it in GitHub Desktop.
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 <stdio.h> | |
| #include <stdlib.h> | |
| #include <signal.h> | |
| void sig_handler(int signo) | |
| { | |
| printf("Signal %d", signo); | |
| exit(1); | |
| } | |
| int install_sig_handler(void) | |
| { | |
| struct sigaction sa; | |
| sa.sa_handler = sig_handler; | |
| sigemptyset(&sa.sa_mask); | |
| sa.sa_flags = 0; | |
| if (sigaction(SIGTERM, &sa, NULL) != 0) { | |
| printf("sigaction(SIGTERM) error\n"); | |
| return -1; | |
| } | |
| if (sigaction(SIGINT, &sa, NULL) != 0) { | |
| printf("sigaction(SIGINT) error\n"); | |
| return -1; | |
| } | |
| if (sigaction(SIGKILL, &sa, NULL) != 0) { | |
| printf("sigaction(SIGKILL) error\n"); | |
| return -1; | |
| } | |
| return 0; | |
| } | |
| int main(int argc, char const* argv[]) | |
| { | |
| install_sig_handler(); | |
| while(1) { | |
| sleep(60); | |
| } | |
| return 0; | |
| } |
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
| #!/bin/bash | |
| proc_term() | |
| { | |
| echo "SIGTERM trapped" | |
| exit 1 | |
| } | |
| trap "proc_term" SIGTERM | |
| proc_kill() | |
| { | |
| echo "SIGTERM trapped" | |
| exit 1 | |
| } | |
| trap "proc_kill" SIGKILL | |
| while true ; do | |
| sleep 60 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment