(pidfile_path)
Write the PID in the named PID file.

        Get the numeric process ID (“PID”) of the current process
        and write it to the named file as a line of text.
Write the PID in the named PID file.
Write the PID in the named PID file .
def write_pid_to_pidfile(pidfile_path):
    """ Write the PID in the named PID file.

        Get the numeric process ID (“PID”) of the current process
        and write it to the named file as a line of text.

        """
    open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY)
    open_mode = 0o644
    pidfile_fd = os.open(pidfile_path, open_flags, open_mode)
    pidfile = os.fdopen(pidfile_fd, 'w')

    # According to the FHS 2.3 section on PID files in /var/run:
    #
    #   The file must consist of the process identifier in
    #   ASCII-encoded decimal, followed by a newline character. For
    #   example, if crond was process number 25, /var/run/crond.pid
    #   would contain three characters: two, five, and newline.

    pid = os.getpid()
    pidfile.write("%s\n" % pid)
    pidfile.close()
def write_pid_to_pidfile ( pidfile_path ) : open_flags = ( os . O_CREAT | os . O_EXCL | os . O_WRONLY ) open_mode = 0o644 pidfile_fd = os . open ( pidfile_path , open_flags , open_mode ) pidfile = os . fdopen ( pidfile_fd , 'w' ) # According to the FHS 2.3 section on PID files in /var/run: # #   The file must consist of the process identifier in #   ASCII-encoded decimal, followed by a newline character. For #   example, if crond was process number 25, /var/run/crond.pid #   would contain three characters: two, five, and newline. pid = os . getpid ( ) pidfile . write ( "%s\n" % pid ) pidfile . close ( )