daemonize icon indicating copy to clipboard operation
daemonize copied to clipboard

Why this lib doesnt fork twice?

Open coldfire-x opened this issue 7 years ago • 2 comments

Readed lots of posts, all mention we should fork twice for daemonize a py process, why this lib dont?

@penpen

coldfire-x avatar Jul 24 '17 15:07 coldfire-x

I am wondering the same...

Spectrik avatar Dec 24 '17 15:12 Spectrik

Double fork is a technique meant to re-parent the daemon process to init. Some investigations show that it does not change its parent, as opposed to what we usually imagine a "daemon" would do.

For example, if you run the usage section of the doc, you may see:

$ ps j $(cat /tmp/test.pid)
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
 2091 21109 21109 21109 ?           -1 Ss    1000   0:00 python3 daemon.py

The number under PPID is the pid of the parent process. On my computer this is the pid of systemd daemon, not init:

$ ps 2091
  PID TTY      STAT   TIME COMMAND
 2091 ?        Ss     0:00 /lib/systemd/systemd --user

Strictly saying, I don't say the package is "daemonizing" the process. But thinking that it makes my script running in background is acceptable to me.

andy0130tw avatar Aug 27 '19 16:08 andy0130tw