A Process' Lifetime A process is only created as a copy of an existing process fork(2) takes no arguments and returns integer It returns 0 in the child and the child's pid in the father Thus, the processes share files, signals and all the rest The child, still running the parent's code, can change itself Any process can change itself, the new child is not special A typical child closes files, changes directory, etc A process can execute a different file, through execve(2) The call never returns: the process is replaced completely All attributes (beside the memory image) remain unchanged A process can wait for children to die, or get notified about it The system sends SIGCHLD to the parent, that can use it The parent can actively wait(2), in blocking or non-blocking mode if (fork() == 0) execlp("sleep", "sleep", "1", NULL); else wait(NULL); exit(0);