/* $OpenBSD: sig-stop.c,v 1.1 2007/04/29 20:10:24 art Exp $ */ /* * Written by Artur Grabowski 2007 Public Domain. */ #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { struct timespec ts; pid_t child; int status; int count; int toggle = 0; switch((child = fork())) { case -1: err(1, "fork"); case 0: ts.tv_sec = 0; ts.tv_nsec = 1000; for (count = 0; count < 100; count++) { nanosleep(&ts, NULL); } exit(0); default: break; } ts.tv_sec = 1; ts.tv_nsec = 0; nanosleep(&ts, NULL); do { toggle ^= 1; if (kill(child, toggle ? SIGSTOP : SIGCONT)) { if (wait(&status) < 0) err(1, "wait"); break; } } while(waitpid(child, &status, WCONTINUED|WUNTRACED) > 0 && (toggle ? WIFSTOPPED(status) : WIFCONTINUED(status))); if (!WIFEXITED(status)) err(1, "bad status: %d\n", status); return 0; }