/*-------------------------------------------------------------------*/ /* testsignalignore.c */ /* Ignoring signals in the parent (but not the child) process. */ /*-------------------------------------------------------------------*/ #include #include #include #define TRUE 1 int main(int argc, char *argv[]) { int iPid; int i; signal(SIGINT, SIG_IGN); iPid = fork(); if (iPid == -1) { printf("Failed to execute fork.\n"); exit(1); } if (iPid == 0) { signal(SIGINT, SIG_DFL); for (i = 0; TRUE; ++i) printf("Child process: %d\n", i); _exit(0); /* Should never reach this line. */ } for (i = 0; TRUE; ++i) printf("Parent process: %d\n", i); return 0; } /* Sample execution: $ testsignalignore 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 ... */ /* Note: Must use kill command to stop parent process. */