Hello
I am starting to understand signal processing in UNIX. I still have some doubts ...
In the following program (not written by me, of course) why is sigint_handler() declared inside main() ?
By the way, could someone give some easy to understand example of the use of the pointer returned by signal ().Code:#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <signal.h> int main(void) { void sigint_handler(int sig); /* prototype */ char s[200]; /* set up the handler */ if (signal(SIGINT, sigint_handler) == SIG_ERR) { perror("signal"); exit(1); } printf("Enter a string:\n"); if (gets(s) == NULL) perror("gets"); else printf("You entered: \"%s\"\n", s); return 0; } /* this is the handler */ void sigint_handler(int sig) { printf("Not this time!\n"); }
Thanks in advance !



LinkBack URL
About LinkBacks


