Created
September 13, 2010 17:52
-
-
Save hannahwhy/577728 to your computer and use it in GitHub Desktop.
a demonstration of signal(3)
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
| 0x0 | |
| 0x1f2e | |
| dummy handler received 99 |
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 <signal.h> | |
| #include <stdio.h> | |
| void | |
| dummy_handler(int signal) | |
| { | |
| printf("dummy handler received %d\n", signal); | |
| } | |
| void | |
| another_dummy_handler(int signal) | |
| { | |
| } | |
| int | |
| main(int argc, char** argv) | |
| { | |
| sig_t initial_handler; | |
| sig_t old_handler; | |
| initial_handler = signal(SIGUSR1, dummy_handler); | |
| /* this will be NULL, because no handler was previously registered */ | |
| printf("%p\n", initial_handler); | |
| old_handler = signal(SIGUSR1, another_dummy_handler); | |
| /* this won't be, and in fact old_handler will equal the address of | |
| * dummy_handler */ | |
| printf("%p\n", old_handler); | |
| /* just to prove what I said above */ | |
| (*old_handler)(99); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment