Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- void sig_handler(int signo) /* signal handler */
- {
- if (signo == SIGINT)
- printf("received SIGINT\n");
- }
- int main(void)
- {
- /* signal(3) can return only 3 dispositions i.e. SIG_DFL, SIG_IGN or SIG_ERR. *
- * After main() calling this fx, whenever SIGINT is delivered to the process, *
- * sig_handler fx will be invoked. This is called signal handler. And we can't *
- * check the current disposition without catching the signal, unless we *
- * explicitly use sigaction(2). *
- * Note that we can't catch or ignore SIGKILL and SIGSTOP. */
- if (signal(SIGINT, sig_handler) == SIG_ERR)
- fprintf(stderr, "can't catch SIGINT\n");
- /* A long wait so that we can easily issue a signal to this process. */
- while (1)
- sleep(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement