Detaching From The Controlling Terminal And Becoming a Daemon These are the steps we take in order to become a daemon: Call fork() and have the parent exit() to make the shell that exec'd us think we're done The child gets a new PID but inherits the parents PGID, so it is guaranteed to not be a session group leader Call setsid() to create a new session. We now become the process group leader of the new session and the new group, and we have no controlling terminal Fork() again to make sure we can never acquire a controlling terminal in the future Change the current working directory Set file mode creation to 0 Close unneeded file descriptors