Reference for proper handling of PID file on Unix

前端 未结 5 2042
故里飘歌
故里飘歌 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:31

    First off, on all modern UNIXes /var/run does not persist across reboots.

    The general method of handling the PID file is to create it during initialization and delete it from any exit, either normal or signal handler.

    There are two canonical ways to atomically create/check for the file. The main one these days is to open it with the O_EXCL flag: if the file already exists, the call fails. The old way (mandatory on systems without O_EXCL) is to create it with a random name and link to it. The link will fail if the target exists.

提交回复
热议问题