def write(create_parents=true)
      FileUtils.mkdir_p(File.dirname(@pid_file)) if create_parents

      # Protip from Wilson: binary mode keeps things sane under Windows
      # Closing the fd releases our lock
      File.open(@pid_file, 'a+b', 0644) do |f|
        f.flock(File::LOCK_EX)

        # Check if process is already running
        pid = f.read().strip().to_i()
        if pid == Process.pid()
          return
        elsif VCAP.process_running?(pid)
          raise ProcessRunningError.new("Process already running (pid=%d)." % (pid))
        end

        # We're good to go, write our pid
        f.truncate(0)
        f.rewind()
        f.write("%d\n" % (Process.pid()))
        f.flush()
      end
    end
def write(create_parents=true)
      FileUtils.mkdir_p(File.dirname(@pid_file)) if create_parents

      # Protip from Wilson: binary mode keeps things sane under Windows
      # Closing the fd releases our lock
      File.open(@pid_file, 'a+b', 0644) do |f|
        f.flock(File::LOCK_EX)

        # Check if process is already running
        pid = f.read().strip().to_i()
        if pid == Process.pid()
          return
        elsif VCAP.process_running?(pid)
          raise ProcessRunningError.new("Process already running (pid=%d)." % (pid))
        end

        # We're good to go, write our pid
        f.truncate(0)
        f.rewind()
        f.write("%d\n" % (Process.pid()))
        f.flush()
      end
    end
Atomically writes the pidfile.
 NB: This throws exceptions if the pidfile contains the pid of another running process.

 +create_parents+  If true, all parts of the path up to the file's dirname will be created.