Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement