#include #include #include #include #include int main (int argc, char **argv) { pid_t pid; if ((pid = fork()) < 0) { perror("fork"); } else if (!pid) { if (daemon(1,1) < 0) { perror("daemon"); exit(-1); } printf("daemon is %d\n",getpid()); sleep(100); exit(0); } printf("middle child is %d (and died)\n",pid); waitpid(pid,NULL,0); printf("parent is %d\n",getpid()); sleep(100); return 0; }