Skip to content

Instantly share code, notes, and snippets.

@hannahwhy
Created September 13, 2010 17:52
Show Gist options
  • Select an option

  • Save hannahwhy/577728 to your computer and use it in GitHub Desktop.

Select an option

Save hannahwhy/577728 to your computer and use it in GitHub Desktop.
a demonstration of signal(3)
0x0
0x1f2e
dummy handler received 99
#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