// fpg - forground process group hypothesis testing #include #include #include #include #include #include #include void logsig(int sig); int main(void) { pid_t parent = getpid(); if (tcsetpgrp(STDIN_FILENO, parent) != 0) err(1, "tcsetpgrp"); pid_t child = fork(); if (child < 0) err(1, "fork failed"); if (child) { signal(SIGINT, logsig); fprintf(stderr, "parent %d\n", parent); int status; waitpid(child, &status, 0); _exit(0); } else { signal(SIGINT, logsig); pid_t newpid = getpid(); fprintf(stderr, " child %d\n", newpid); sleep(999); _exit(0); } } void logsig(int sig) { fprintf(stderr, "SIG %d -> %d\n", sig, getpid()); _exit(0); }