fork(1) download
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <inttypes.h>
  5.  
  6. static void catch_function(int signal) {
  7. int foo;
  8. printf("Local variable address: %"PRIxPTR"\n", (intptr_t)&foo);
  9. }
  10.  
  11. int main(void) {
  12. int bar;
  13. if (signal(SIGINT, catch_function) == SIG_ERR) {
  14. fputs("An error occurred while setting a signal handler.\n", stderr);
  15. return EXIT_FAILURE;
  16. }
  17. printf("Local variable address: %"PRIxPTR"\n", (intptr_t)&bar);
  18. puts("Raising the interactive attention signal.");
  19. if (raise(SIGINT) != 0) {
  20. fputs("Error raising the signal.\n", stderr);
  21. return EXIT_FAILURE;
  22. }
  23. puts("Exiting.");
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
Local variable address: bf9d47c4
Raising the interactive attention signal.
Local variable address: bf9d4498
Exiting.