/*-------------------------------------------------------------------*/ /* testsignalfork.c */ /* Ignoring signals in the parent (but not the child) process. */ /*-------------------------------------------------------------------*/ #include #include #include #include #include int main(int argc, char *argv[]) { int iPid; int i = 0; signal(SIGINT, SIG_IGN); fflush(NULL); iPid = fork(); if (iPid == -1) {perror(argv[0]); return 1; } if (iPid == 0) { signal(SIGINT, SIG_DFL); while (1) { printf("Child process: %d\n", i); i++; } exit(1); /* Should never reach this line. */ } while (1) { printf("Parent process: %d\n", i); i++; } wait(NULL); return 0; } /* Sample execution: $ gcc -Wall -ansi -pedantic -o testsignalfork testsignalfork.c $ testsignalfork Parent process: 0 Parent process: 1 ... Child process: 0 Child process: 1 ... ^C <- Kills child process, but not parent process Parent process: 12345 Parent process: 12346 ... */