/* * sig.c: sample program starter kit for manipulating signals using signal(). * Not everything is demonstrated; this is just a starter kit. */ #include #include void nyahnyah(int signum); const int BUFSIZE = 256; int main() { char line[BUFSIZE]; /* Activate one of the following lines, depending on whether you want interrupt signals just ignored, or would like the specified function called */ signal(SIGINT, SIG_IGN); //signal(SIGINT, nyahnyah); /* SIGTSTP is the signal generated by ^Z, the suspend process signal */ signal(SIGTSTP, nyahnyah); while(fgets(line, BUFSIZE, stdin) != NULL) { printf("You typed => %s", line); } } void nyahnyah(int signum) { /* supposedly need to reset this here (per "man signal" and it's discussion of signals under linux), but doesn't actually seem to matter. Documentation != observed program behavior. */ //signal(signum, nyahnyah); fprintf(stderr, "nyah, nyah signal #%d.\n", signum); }