Set the worker pid file

@param  string     $pidFile Filename to store pid in
@throws \Exception
554498
public function setPidFile($pidFile)
    {
        $dir = realpath(dirname($pidFile));
        $filename = basename($pidFile);

        if (substr($pidFile, -1) == '/' or $filename == '.') {
            throw new \InvalidArgumentException('The pid file "'.$pidFile.'" must be a valid file path');
        }

        if (!is_dir($dir)) {
            throw new \RuntimeException('The pid file directory "'.$dir.'" does not exist');
        }

        if (!is_writeable($dir)) {
            throw new \RuntimeException('The pid file directory "'.$dir.'" is not writeable');
        }

        $this->pidFile = $dir.'/'.$filename;

        if (file_exists($this->pidFile) and posix_kill((int)trim(file_get_contents($this->pidFile)), 0)) {
            throw new \RuntimeException('Pid file "'.$pidFile.'" already exists and worker is still running.');
        }

        if (!file_put_contents($this->pidFile, getmypid(), LOCK_EX)) {
            throw new \RuntimeException('Could not write pid to file "'.$pidFile.'"');
        }
    }
829486
public function setPid($pid)
    {
        if ($this->status != self::STATUS_NEW) {
            throw new \RuntimeException('Cannot set worker pid after worker has started working');
        }

        $this->pid = (int)$pid;
    }
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 */ }
      }
    }
1089316
public function setTargetFile($file)
    {
        if (is_string($file)) {
            $file = new PhingFile($file);
        }
        $this->_targetFile = $file;
    }
1111697
public function set(string $name, UploadedFileInterface $uploadedFile): void
    {
        $this->uploadedFiles[$name] = $uploadedFile;
    }
167254
def write_pid_file(fn):
    
    if not fn:
        return None
    if fn == '' or fn == "''":
        # work around argument passings in init-scripts
        return None
    f = open(fn, "w")
    f.write("%s\n" % (os.getpid()))
    f.close()
931227
public function execute(string $fid)
    {
        if (!isset($this->template[$fid])) {
            throw new TemplateFailException("No `Html` Template File", "200");
        }
        $tpl = $this->template[$fid];

        $cplPath = $this->setCompileWithTemplateFile($tpl[1]);
        $this->includeTpl($cplPath);
    }
705120
public function setSrcfile($file)
    {
        if (is_string($file)) {
            $file = new PhingFile($file);
        }
        $this->_sourceFile = $file;
    }
991782
def live_pidfile(pidfile): # pragma: no cover
    
    pid = read_pidfile(pidfile)
    if pid:
        try:
            kill(int(pid), 0)
            return pid
        except OSError as e:
            if e.errno == errno.EPERM:
                return pid
    return None
1170792
public final void setDestFile(final String destFile) {
        if (SwingUtilities.isEventDispatchThread()) {
            setDestFileIntern(destFile);
        } else {
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        setDestFileIntern(destFile);
                    }
                });
            } catch (final Exception ex) {
                ignore();
            }
        }
    }
112873
protected function loadPids() : void
    {
        foreach ($this->poolsConfig as $pool => $poolConfig) {
            $pidFiles = glob($this->runPath . '/' . $pool . '/*.pid');
            foreach ($pidFiles as $pidFile) {
                $workerId = basename($pidFile, '.pid');
                $pid = file_get_contents($pidFile);
                if ($this->pidIsValid($pid, $workerId)) {
                    $this->pids[$pool][$workerId] = $pid;
                } else {
                    $this->removePidFile($pidFile);
                }
            }
        }
    }
1089510
public static function setFile($file)
    {
        if (is_file($file)) {
            $options = Yaml::parse(file_get_contents($file));
            self::$instance = new self($options);
            self::$instance->validateOptions();
        } else {
            throw new Exception("Can't find config file at ".$file);
        }
    }
592966
public function setID($id)
    {
        if($id !== null && substr($id, 0, 1) !== '/')
            throw new Exception("invalid file id, must start with a /");
        $this->id = $id;
    }
895626
public function set_file($file) {
        if (!file_exists($file) || (!is_readable($file))) {
            throw new progressive_parser_exception('invalid_file_to_parse');
        }
        $this->file = $file;
        $this->contents = null;
    }
662106
public function start()
    {
        if (extension_loaded('pcntl')) {
            pcntl_signal(SIGINT, function ($sig) {
                $this->stop();
            });
        }

        if (false === file_put_contents($this->myPidFile, getmypid())) {
            throw new \RuntimeException('Cannot save the pid in pid file.');
        }
        if (!$this->server->isConnected()) {
            throw new \Exception('Cannot start: not connected');
        }
        $this->server->onFound($this->onConnectPeer());
        register_shutdown_function(function () {
            $this->stop();
        });
//        $this->server->block();
        $this->work();
    }
79730
private function _createFile($pFile)
    {
        $pathInfo = pathinfo($pFile);

        $dir = $pathInfo['dirname'];
        if (! DirecoryData::create($dir)) {
            throw new Exception("Unable to create the cache directory '$dir'");
        }

        if (! is_readable($pFile) and ! FileData::create($pFile, self::DEFAULT_CONTENT)) {
            throw new Exception("Unable to create the cache file '$pFile'");
        }

        return $this;
    }
704098
protected function runWorker($id, $pid)
    {
        $this->isWorker = true;
        $this->isMaster = false;

        $this->id = $id;
        $this->masterPid = $this->pid;
        $this->pid = getmypid();

        $eCode = $this->receiveTasks($this->queue);

        $this->log("Worker #$id exited(Exit-Code:$eCode)", ProcessLogger::PROC_INFO);
        $this->quit($eCode);
    }