#include #include #include #include #include const int EX_RUNERR = 127; int main(int argc, char* argv[]) { /* arguments */ if (argc != 2) { std::cerr << "Usage: " << argv[0] << " WAIT_SECONDS" << std::endl; exit(EXIT_FAILURE); } int wait_time = atoi(argv[1]); /* fork */ pid_t pid = fork(); char* const program = const_cast("./forever"); char* const program_argv[] = { NULL }; /* parent */ if (pid) { if (pid == -1) { exit(EXIT_FAILURE); } sleep(wait_time); if (kill(pid, SIGSTOP) == -1) { exit(EXIT_FAILURE); } sleep(wait_time); if (kill(pid, SIGCONT) == -1) { exit(EXIT_FAILURE); } sleep(wait_time); if (kill(pid, SIGKILL) == -1) { exit(EXIT_FAILURE); } waitpid(pid, NULL, 0); } /* child */ else { execv(program, program_argv); exit(EX_RUNERR); } exit(EXIT_SUCCESS); }