int main (int argc _GL_UNUSED_PARAMETER, char *argv[]) { pid_t ppid; set_program_name (argv[0]); signal (SIGTERM, doexit); /* Parent exits nicely at SIGTERM. */ ppid = waitdaemon (0, 0, 5); /* Five seconds of delay. */ /* Child should return here before parent. */ if (ppid > 0) kill (ppid, SIGTERM); /* Bless the parent process. */ /* Only grand child reaches this statement. */ return EXIT_FAILURE; }
int daemon (int nochdir, int noclose) { return (waitdaemon (nochdir, noclose, 0) == -1) ? -1 : 0; }