Reference for proper handling of PID file on Unix

前端 未结 5 2045
故里飘歌
故里飘歌 2020-11-29 21:08

Where can I find a well-respected reference that details the proper handling of PID files on Unix?

On Unix operating systems, it is common practice

5条回答
  •  醉酒成梦
    2020-11-29 21:29

    The systemd package on Red Hat 7 provides a man page daemon(7) with the header line "Writing and packaging system daemons."

    This man page discusses both "old style" (SysV) and "new style" (systemd) daemonization. In new style, systemd itself handles the PID files for you (if so configured to do so). However, in old style, the man page has this to say:

    1. In the daemon process, write the daemon PID (as returned by getpid()) to a PID file, for example /run/foobar.pid (for a hypothetical daemon "foobar") to ensure that the daemon cannot be started more than once. This must be implemented in race-free fashion so that the PID file is only updated when it is verified at the same time that the PID previously stored in the PID file no longer exists or belongs to a foreign process.

    You can also read this man page online.

提交回复
热议问题