Stop a running server.

@param string $address
@param int|null $pid

@return bool
True on success, false on failure.
351509
protected function stopServer($address, $pid = null)
    {
        $success = true;
        if ($pid && function_exists('posix_kill')) {
            /** @noinspection PhpComposerExtensionStubsInspection */
            $success = posix_kill($pid, SIGTERM);
            if (!$success) {
                /** @noinspection PhpComposerExtensionStubsInspection */
                $this->stdErr->writeln(sprintf(
                    'Failed to kill process <error>%d</error> (POSIX error %s)',
                    $pid,
                    posix_get_last_error()
                ));
            }
        }
        $pidFile = $this->getPidFile($address);
        if (file_exists($pidFile)) {
            $success = unlink($pidFile) && $success;
        }
        unset($this->serverInfo[$address]);
        $this->saveServerInfo();

        return $success;
    }
1113944
public static function stop() {
		if (!self::is_running()) {
			throw new \Exception('Transaction daemon is not running');
		}

		$pid = file_get_contents(Config::$pid_file);
		$return = posix_kill($pid, 15);
		if ($return === false) {
			throw new \Exception('Unable to kill daemon');
		}
		Transaction::unlock_all();
		return true;
	}
313105
public function stop() {
		if( $this->started ) {
			exec(sprintf('kill %d',
				$this->pid));
		}

		$this->started = false;
	}
1225199
def stop

      if running?

        Process.kill(@signal, @pid)
        FileUtils.rm(@pid_file)

        execute_callback(:stop)

        begin
          Process.wait(@pid)
        rescue Errno::ECHILD
        end

        @timeout.downto(0) do
          sleep 1
          exit unless running?
        end

        Process.kill 9, @pid if running?
        execute_callback(:after_stop)

      else
        FileUtils.rm(@pid_file) if File.exists?(@pid_file)
        log(:info, "\"#{@name}\" PID file not found.")
      end

    rescue Errno::ENOENT
    end
553521
public function stopProcess()
    {
        $this->isCurrentOsSupported('Only on *nix-based systems process cna be destroyed. You are running "%s".');
        try {
            $result = shell_exec(sprintf('kill %d 2>&1', $this->pid));
            if (!preg_match('/No such process/', $result)) {
                return true;
            }
        } catch (Exception $e) {

        }

        return false;
    }
410589
protected function _killPid()
    {
        if (file_exists($this->_pidFile)) {
            unlink($this->_pidFile);
        }
        if ($this->_pid) {
            posix_kill($this->_pid, SIGTERM);
        }
    }
551954
def daemon_stop(pidfile, sig=None):
    
    logger.debug("stop daemon application pidfile={pidfile}.".format(pidfile=pidfile))
    pid = load_pid(pidfile)
    logger.debug("load pid={pid}".format(pid=pid))
    if not pid:
        six.print_("Application is not running or crashed...", file=os.sys.stderr)
        os.sys.exit(195)
    process_kill(pid, sig)
    return pid
518469
public function isRunning(int $pid): bool
    {
        $cmd = sprintf('kill -0 %d 2>&1', $pid);
        $this->logger->debug(__METHOD__ . ": Exec command: $cmd");
        exec($cmd, $output, $return_var);

        return $return_var === 0;
    }
1327359
protected void kill( String pid )
        throws IOException, InterruptedException
    {
        String os = System.getProperty( "os.name" );
        String command = ( os.startsWith( "Windows" ) ) ? "taskkill /F /PID " + pid : "kill " + pid;
        Runtime.getRuntime().exec( command ).waitFor();
    }
1233189
public static function sendSignal(int $pid, int $signal, int $timeout = 0): bool
    {
        if ($pid <= 0 || !self::hasPosix()) {
            return false;
        }

        // do send
        if ($ret = \posix_kill($pid, $signal)) {
            return true;
        }

        // don't want retry
        if ($timeout <= 0) {
            return $ret;
        }

        // failed, try again ...
        $timeout = $timeout > 0 && $timeout < 10 ? $timeout : 3;
        $startTime = \time();

        // retry stop if not stopped.
        while (true) {
            // success
            if (!$isRunning = @posix_kill($pid, 0)) {
                break;
            }

            // have been timeout
            if ((\time() - $startTime) >= $timeout) {
                return false;
            }

            // try again kill
            $ret = \posix_kill($pid, $signal);
            \usleep(10000);
        }

        return $ret;
    }
162089
public function stop( $_signal = SIGKILL, $_wait = false ) {
		if( $this->isAlive() ) {
			posix_kill( $this->pid, $_signal );
			if( $_wait ) {
				pcntl_waitpid( $this->pid, $status = 0 );
			}
		}
	}
84104
public static function kill($pid, $force = false, $timeout = 3)
    {
        return self::sendSignal($pid, $force ? SIGKILL : SIGTERM, $timeout);
    }
1119008
public static function sendSignal($pid, $signal, $timeout = 0)
    {
        if ($pid <= 0) {
            return false;
        }

        // do send
        if ($ret = posix_kill($pid, $signal)) {
            return true;
        }

        // don't want retry
        if ($timeout <= 0) {
            return $ret;
        }

        // failed, try again ...

        $timeout = $timeout > 0 && $timeout < 10 ? $timeout : 3;
        $startTime = time();

        // retry stop if not stopped.
        while (true) {
            // success
            if (!$isRunning = @posix_kill($pid, 0)) {
                break;
            }

            // have been timeout
            if ((time() - $startTime) >= $timeout) {
                return false;
            }

            // try again kill
            $ret = posix_kill($pid, $signal);
            usleep(10000);
        }

        return $ret;
    }
551141
protected function killProcess($pid, $sig, $wait = 0)
    {
        Process::kill($pid, $sig);

        if ($wait) {
            $start = time();

            do {
                if (! $this->isRunning($pid)) {
                    break;
                }

                usleep(100000);
            } while (time() < $start + $wait);
        }

        return $this->isRunning($pid);
    }
1179861
def stop(self):
        
        self.is_alive = False
        self.server_close()
        flows.Global.LOGGER.info("Server Stops " + (str(self.server_address)))
1003146
public function kill()
    {
        if ($this->pid < 1) {
            return;
        }

        if (!posix_kill($this->pid, SIGTERM)) {
            throw new \RuntimeException('Unable to kill process, PID: '.$this->pid.'.');
        }

        return;
    }
1252021
protected function cancelRequest($pid, $ex)
    {
        $callback = $this->reqs[$pid]->onCancel();
        unset($this->reqs[$pid]);
        $callback($ex);
    }