Save pid.

@throws Exception
187895
protected static function saveMasterPid()
    {
        if (static::$_OS !== OS_TYPE_LINUX) {
            return;
        }

        static::$_masterPid = posix_getpid();
        if (false === file_put_contents(static::$pidFile, static::$_masterPid)) {
            throw new Exception('can not save pid to ' . static::$pidFile);
        }
    }
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'))
        }
    }
46985
def save_exit_status(pid)
        logger.debug "Spawning thread to monitor process ID #{pid}"
        @success = nil
        Thread.start do
          logger.debug "Thread started, waiting for PID #{pid}"
          status = Process.waitpid2(pid).last.exitstatus
          logger.debug "Process exited with status #{status}"
          @success = (status == 0)
        end
      end
771570
public void commit() throws Exception {
        final Map<String, Object> params = new HashMap<String, Object>();

        final String applicationId = getPropertyAsString("applicationId");
        if (applicationId != null) params.put("applicationId", applicationId);

        final String name = getName();
        if (name != null) params.put("name", name);

        final String fallbackNumber = getFallbackNumber();
        if (fallbackNumber != null) params.put("fallbackNumber", fallbackNumber);

        final String uri = getUri();
        client.post(uri, params);

        final JSONObject object = toJSONObject(client.get(uri, null));
        updateProperties(object);
    }
824120
public function save()
    {
        $this->getHandler()->write($this->getId(), serialize($this->attributes));
        $this->started = false;
    }
290273
public function save($chmod = null)
    {
        if ($this->modified) {
            if (false === @file_put_contents($this->filename, $this->generateIni())) {
                throw new \Exception('Impossible to write into '.$this->filename);
            } elseif ($chmod) {
                chmod($this->filename, $chmod);
            }
            $this->modified = false;
        }
    }
135627
protected function createPidFile()
    {
        $pidFile = $this->getPidFile();
        $pid = $this->container->make(Server::class)->master_pid;

        file_put_contents($pidFile, $pid);
    }
619580
public static void kill(final long pid) throws IOException, InterruptedException {
    if (isUnix()) {
      final Process process = new ProcessBuilder()
          .command("bash", "-c", "kill", "-9", String.valueOf(pid))
          .start();
      final int returnCode = process.waitFor();
      LOG.fine("Kill returned: " + returnCode);
    } else if (isWindows()) {
      final Process process = new ProcessBuilder()
          .command("taskkill.exe", "/f", "/pid", String.valueOf(pid))
          .start();
      final int returnCode = process.waitFor();
      LOG.fine("Kill returned: " + returnCode);
    } else {
      throw new UnsupportedOperationException("Unable to execute kill on unknown OS");
    }
  }
948918
private function createSavegame()
    {
        // the current process will become the savegame
        $this->savegame = \posix_getpid();

        $pid = \pcntl_fork();
        if ($pid < 0) {
            throw new \RuntimeException('Unable to create savegame fork');
        } elseif ($pid > 0) {
            // we're the savegame now... let's wait and see what happens
            \pcntl_waitpid($pid, $status);

            // worker exited cleanly, let's bail
            if (!\pcntl_wexitstatus($status)) {
                \posix_kill(\posix_getpid(), SIGKILL);
            }

            // worker didn't exit cleanly, we'll need to have another go
            $this->createSavegame();
        }
    }
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)
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.");
    }
  }
1372964
protected function saveArchive() {
        if (!$this->archive->close() || !$this->archive->open($this->tempFile)) {
            throw new \Exception("Saving archive failed.");
        }
    }
1293424
def __writepid(self, pid):
        
        import tempfile
        d = tempfile.gettempdir()
        name = os.path.join(d, "hoverpy.%i.%i"%(self._proxyPort, self._adminPort))
        with open(name, 'w') as f:
            f.write(str(pid))
            logging.debug("writing to %s"%name)
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();
    }
246187
public function savePid($pid, JobReportInterface $report)
    {
        $report->setPid($pid);
        $this->reportManager->add($report, true);
    }
664546
protected function savePhp()
    {
        $factory = new FilterFactory();
        $filter = $factory->create($this->config);
        $filteredService = $filter->filter($this->service);
        $service = $filteredService->getClass();
        $filteredTypes = $filteredService->getTypes();
        if ($service == null) {
            throw new Exception('No service loaded');
        }

        $output = new OutputManager($this->config);

        // Generate all type classes
        $types = array();
        foreach ($filteredTypes as $type) {
            $class = $type->getClass();
            if ($class != null) {
                $types[] = $class;
            }
        }

        $output->save($service, $types);
    }
307875
public function Save() {
    if (!$this->Validate()) {
      throw new \Exception("Validation failed");
    }

    $file = self::File($this->id);
    if (!is_dir(dirname($file))) {
      mkdir(dirname($file), 0755, true);
    }

    file_put_contents($file, serialize($this), LOCK_EX);
    return $this;
  }