Reputation: 10613
What are the perils of not calling setsid()
when daemonizing a process?
Upvotes: 3
Views: 1238
Reputation: 12670
When a user logs out from a session, all processes associated with that session are killed. For processes that are daemons you do not want this to happen. The solution is to call setsid. Provided that the daemon is not already a process group leader (which it will not be following the fork performed above), this will:
- start a new session, with the daemon as session leader and with no controlling terminal, and
- start a new process group, with the daemon as process group leader.
from here
So basically, if you don't give it a new session id, it can be killed unintentionally.
Upvotes: 6