Created
July 24, 2018 05:55
-
-
Save geekoff7/b498b62cfe8c279548feb29e829566c0 to your computer and use it in GitHub Desktop.
signal handler function in c program
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 <string.h> | |
| #include <unistd.h> | |
| #include <signal.h> | |
| volatile sig_atomic_t please_stop; | |
| void handler_sigint() | |
| { | |
| please_stop = 1; | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| printf("%d \n", getpid()); | |
| signal(SIGINT, handler_sigint); | |
| while (please_stop == 0) | |
| { | |
| sleep(1); | |
| write(1, ".", 1); | |
| } | |
| if (please_stop == 1) | |
| { | |
| write(1, "clean !!!", 10); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment