IN order to create a service(daemon) we fork the parent and make it to exit while making the child to be the session leader by calling setsid()
.
Moreover why do we use setsid()?Our orphan process is taken care of by init
(though in not all cases) process.
Why do we use stsid()?
Is there any relation between setsid()
and handling SIGHUP
signal.
Best Answer
We use setsid() because if we just kill the parent the child will be killed too, the setsid()
The parent is the first process group leader, killing it - or killing the session/terminal - kills the group, which is why we switch the leader (and create a new session while we're at it).