Write the pid file.
963940
function write(conf) {
  var contents = process.pid + EOL
    , file = conf.get(ConfigKey.PIDFILE);
  // can be the empty string
  if(file) {
    try {
      fs.writeFileSync(file, contents);
      log.notice('wrote pid %s to %s', process.pid, file);
    }catch(e) {
      log.warning('failed to write pid file (%s): %s', file, e.message);
    }
  }
}
257537
@Override
  public synchronized void onNext(final RuntimeStart startTime) {
    if (this.isPidNotWritten()) {
      final long pid = OSUtils.getPID();
      final File outfile = new File(PID_FILE_NAME);
      LOG.log(Level.FINEST, "Storing pid `" + pid + "` in file " + outfile.getAbsolutePath());
      try (final PrintWriter p = new PrintWriter(PID_FILE_NAME, "UTF-8")) {
        p.write(String.valueOf(pid));
        p.write("\n");
      } catch (final FileNotFoundException | UnsupportedEncodingException e) {
        LOG.log(Level.WARNING, "Unable to create PID file.", e);
      }
      this.pidIsWritten = true;
    } else {
      LOG.log(Level.FINEST, "PID already written.");
    }
  }
441776
def write_pid(self, pid=None):
    """"""
    pid = pid or os.getpid()
    self.write_metadata_by_name(self._name, 'pid', str(pid))
1039203
def pid(self, pidnum):
        """"""
        try:

            with open(self.pidfile, "w+") as pidfile:

                pidfile.write("{0}\n".format(pidnum))

        except IOError:

            LOG.exception("Failed to write pidfile {0}).".format(self.pidfile))
            sys.exit(exit.PIDFILE_INACCESSIBLE)
380487
def write_data(self):
        """"""
        self.output_file.write(self.downloaded_file_buffer)
        self.output_file.close()
        self.finished_flag = True
1017131
function writePIDFile(pid, name) {
  var pidFilePath = pidDir + name + '.pid';
  exec('mkdir -p ' + pidDir, function(err, stdout, stderr) {
    if (err) {
      winston.error('[forewoman] Error creating the pids directory');
      winston.error(err.message);
    } else {
      fs.writeFileSync(pidFilePath, pid);
    }
  });
}
1108905
def write
      begin
        FileUtils.mkdir_p(@pid_dir)
        open(@pid_file,'w') { |f| f.write(Process.pid) }
        File.chmod(0644, @pid_file)
      rescue StandardError => e
        ErrorTracker.log(self, "Failed to create PID file", e, nil, :caller)
        raise
      end
      true
    end
1126407
def write_pid(file)
      begin
        File.open(file, "w") do |pid_file|
          pid_file.puts(Process.pid)
        end
      rescue
        @logger.fatal("could not write to pid file", :pid_file => file)
        @logger.fatal("SENSU NOT RUNNING!")
        exit 2
      end
    end
902318
function(){
        var bundle = self.bundle;
        var PID = self.PID;
        var proc = self.proc;
        var path = self.path
        //Get PID path.
        if (
            typeof(bundle) != "undefined" && bundle != ""
            && typeof(PID) != "undefined" && PID != "" && PID != null
            && typeof(proc) != "undefined" && proc != "" && proc != null
        ) {
            try {
                var fileStream = fs.createWriteStream(path + PID);
                fileStream.once('open', function(fd) {
                    fileStream.write(bundle);
                    console.debug('registered ', self.proc.pid);
                    fileStream.end();
                    self.emit('proc#complete', false)
                });
            } catch (err) {
                self.emit('proc#complete', err)
            }

        } else {
            self.emit('proc#complete', new Error('encountered troubles while trying to save Process file'))
        }
    }
124720
def pid
      contents = File.read(self.pid_file).strip rescue ''
      real_pid = contents =~ /^\d+$/ ? contents.to_i : nil

      if real_pid
        @pid = real_pid
        real_pid
      else
        @pid
      end
    end
155847
def _write(self, str_buf):
    """"""
    self._filehandle.write(str_buf)
    self._buf_size += len(str_buf)
905035
def write_file(self, fp, data):
        """"""
        with open(fp, 'w') as f:
            f.write(data)
1173569
def create_pid_file(process_name):
    
    pid_filename = get_pid_filename(process_name)
    try:
        with open(pid_filename, mode='w') as pid_file:
            pid_file.write(str(os.getpid()))
    except Exception as e:
        print('Unable to create pid file at: {0}, because of: {1}'.format(pid_filename, e),
              file=sys.stderr)
956825
def cleanup(self):
        """"""
        try:
            os.remove(self.pid_file)
        except OSError as exc:
            logger.critical("Could not remove pid_file: %s", exc)

        # Save the final status of the flow.
        self.flow.pickle_dump()
98130
def write_pid(pidfile):
    
    pid = str(os.getpid())
    try:
        with open(pidfile, mode='w') as _file:
            print("writing processID {p} to pidfile".format(p=pid))
            _file.write(pid)
    except OSError as exc:
        sys.exit("failed to write pidfile:{e}".format(e=exc))
137332
def _write_pidfile(self):
        """"""
        flags = os.O_CREAT | os.O_RDWR
        try:
            # Some systems don't have os.O_EXLOCK
            flags = flags | os.O_EXLOCK
        except AttributeError:
            pass
        self._pid_fd = os.open(self.pidfile, flags, 0o666 & ~self.umask)
        os.write(self._pid_fd, str(os.getpid()).encode('utf-8'))
931819
private static void writePid(String file, boolean ignorePidFile) {
      File pidFile = new File(file);
      if(pidFile.exists()) {
        Long oldPid = getPid(pidFile);
        if(oldPid==null) {
          pidFile.delete();
        } else {
          log.warn("\n\t==================================\n\tThe OpenTSDB PID file [" + file + "] already exists for PID [" + oldPid + "]. \n\tOpenTSDB might already be running.\n\t==================================\n");
          if(!ignorePidFile) {
            log.warn("Exiting due to existing pid file. Start with option --ignore-existing-pid to overwrite"); 
            System.exit(-1);
          } else {
            log.warn("Deleting existing pid file [" + file + "]");
            pidFile.delete();
          }
        }
      }
      pidFile.deleteOnExit();
      File pidDir = pidFile.getParentFile();
      FileOutputStream fos = null;
      try {
        if(!pidDir.exists()) {
          if(!pidDir.mkdirs()) {
            throw new Exception("Failed to create PID directory [" + file + "]");
          }
        }     
        fos = new FileOutputStream(pidFile);      
        String PID = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
        fos.write(String.format("%s%s", PID, EOL).getBytes());
        fos.flush();
        fos.close();
        fos = null;
        log.info("PID [" + PID + "] written to pid file [" + file + "]");
      } catch (Exception ex) {
        log.error("Failed to write PID file to [" + file + "]", ex);
        throw new IllegalArgumentException("Failed to write PID file to [" + file + "]", ex);
      } finally {
        if(fos!=null) try { fos.close(); } catch (Exception ex) { /* No Op */ }
      }
    }