Alexander Suraphel
Alexander Suraphel

Reputation: 10613

What is the effect of leaving the call setsid() when creating daemon processes?

What are the perils of not calling setsid() when daemonizing a process?

Upvotes: 3

Views: 1238

Answers (1)

Jean-Bernard Pellerin
Jean-Bernard Pellerin

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:

  1. start a new session, with the daemon as session leader and with no controlling terminal, and
  2. 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

Related Questions