Check whether a pid is running.

@throws Exception\InvalidArgumentException

@param int $pid

@return bool
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;
    }
995830
public function isLocked($recover = true) {
        $myPid = getmypid();
        if (!file_exists($this->pidFile)) {
            return false;
        }

        $lockPid = trim(file_get_contents($this->pidFile));

        // This is my lockfile, nothing to do
        if ($myPid == $lockPid) {
            return false;
        }

        // Is the PID running?
        $isRunning = $this->isProcessRunning($lockPid);

        // No? Unlock and return Locked=false
        if (!$isRunning) {
            if ($recover) {
                $this->unlock($this->pidFile);
            }
            return false;
        }

        // Someone else is already running
        return true;
    }
911186
def running(processid):
    
    try:
        # From kill(2)
        #   If sig is 0 (the null signal), error checking is performed but no
        #   signal is actually sent. The null signal can be used to check the
        #   validity of pid
        os.kill(processid, 0)
    except OverflowError as exc:
        print("checking validity of pid ({p}) failed with: {e}"
              .format(p=processid, e=exc))
        sys.exit(1)
    except OSError:
        return False
    else:
        return True
245317
function isRunning(pid, callback) {
    if (!pid) {
        return callback(false);
    }

    cp.exec(util.format(process.platform === 'win32' ?
        'tasklist /fi "PID eq %s" | findstr /i "node.exe"'
        : 'ps -f -p %s | grep "node"', pid),
        function (err, stdout, stderr) {
            callback(!err && !!stdout.toString().trim());
        });
}
15746
public function getRunningPID() {
        if (!file_exists($this->pidFile)) {
            return false;
        }

        $runPid = trim(file_get_contents($this->pidFile));
        if (!$runPid) {
            return false;
        }

        return $runPid;
    }
654803
protected function is_process_running() {
	    $lockData = get_option($this->identifier . '_process_lock', null);

	    if (!empty($lockData) || isset($lockData['expires'])) {
            if (time() <= $lockData['expires']) {
                Logger::info('Lock still active.  Expires in: '.($lockData['expires'] - time()));

                return true;
            } else {
                Logger::info("Lock expired");
            }
        }

        if (!empty($lockData)) {
            delete_option($this->identifier . '_process_lock');
        } else {
            Logger::info('No lock data.');
        }

        return false;
	}
700297
public static function markParent($pid)
    {
        $coroutineId = \Swoole\Coroutine::getuid();
        if($coroutineId == $pid){
            return false;
        }
        static::$stackTree[$coroutineId] = $pid;
        return true;
    }
565424
def is_running(pid):
    
    process = get_process(pid)
    if process and process.is_running() and process.status() != "zombie":
        return True
    else:
        return False
201938
protected function determine_id( $pid ) {
		global $wp_query;
		if ( $pid === null &&
			isset($wp_query->queried_object_id)
			&& $wp_query->queried_object_id
			&& isset($wp_query->queried_object)
			&& is_object($wp_query->queried_object)
			&& get_class($wp_query->queried_object) == 'WP_Post'
		) {
			$pid = $wp_query->queried_object_id;
		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) {
			//hack for static page as home page
			$pid = $wp_query->queried_object_id;
		} else if ( $pid === null ) {
			$gtid = false;
			$maybe_post = get_post();
			if ( isset($maybe_post->ID) ) {
				$gtid = true;
			}
			if ( $gtid ) {
				$pid = get_the_ID();
			}
			if ( !$pid ) {
				global $wp_query;
				if ( isset($wp_query->query['p']) ) {
					$pid = $wp_query->query['p'];
				}
			}
		}
		if ( $pid === null && ($pid_from_loop = PostGetter::loop_to_id()) ) {
			$pid = $pid_from_loop;
		}
		return $pid;
	}
81153
public function getPid()
    {
        $options = static::getOptions();
        $debug = @$options['debug'] === true;

        $pidFile = $options['pid_file'];
        if (!$pidFile)
            throw new \Exception("No pid_file in the config");

        $fpPid = fopen($pidFile, "c");
        if (!$fpPid)
            throw new \Exception("Could not open " . $pidFile);

        if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
            fclose($fpPid);
            return (int)file_get_contents($pidFile);
        }

        flock($fpPid, LOCK_UN);
        fclose($fpPid);
        @unlink($pidFile);
        return false;
    }
34406
public static function isRunning($file)
    {
        if (!extension_loaded('posix')) {
            throw new \Exception('posix extension required');
        }

        if (!is_readable($file)) {
            return false;
        }

        if (($lock = @fopen($file, 'c+')) === false) {
            throw new \Exception('unable to open pid file ' . $file);
        }

        if (flock($lock, LOCK_EX | LOCK_NB)) {
            return false;
        } else {
            flock($lock, LOCK_UN);
            return true;
        }
    }
147789
def _is_pid_running_on_windows(pid):
    """"""
    pid = str(pid)

    # Hide flashing command prompt
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

    process = subprocess.Popen(r'tasklist /fi "PID eq {0}"'.format(pid),
                               stdout=subprocess.PIPE,
                               stderr=subprocess.STDOUT,
                               startupinfo=startupinfo)
    stdoutdata, stderrdata = process.communicate()
    stdoutdata = to_text_string(stdoutdata)
    process.kill()
    check = pid in stdoutdata

    return check
1031315
function pidFind(pid) {
  if (!_.isFinite(pid)) return false;
  try {
    if (runningAsRoot()) {
      return process.kill(pid, 0);
    } else {
      return !!ps(pid);
    }
  } catch (e) {
    return false;
  }
}
858787
protected function existsResponse($pid)
    {
        return isset($this->reps[$pid]) || isset($this->handledReps[$pid]);
    }
131286
public function wait() {
        if ($this->pid) {
            \pcntl_waitpid($this->pid, $status, WUNTRACED);
            return $status;
        } else {
            return false;
        }
    }
1272985
public function isProcessRunning(bool $throwsException = false): bool
    {
        $running = false;
        try {
            $pid = $this->getPid();
            $isRunning = $this->process->isRunning($pid);
            if ($isRunning) {
                $this->logger->debug("Pid '${pid}' running.");
                $running = true;
            } else {
                $this->logger->debug("Pid '${pid}' not running.");
            }
        } catch (Exception\PidNotFoundException $e) {
            if ($throwsException) {
                throw $e;
            }
        }

        return $running;
    }
876885
public function actionStatus()
    {
        $pid = $this->getMasterPid();
        Console::stdout("beyod($pid) is running ...\r\n");
        Console::stdout("php ini: ".php_ini_loaded_file()."\r\n");
        Console::stdout("php version: ".phpversion()."\r\n");
        Console::stdout("necessary extensions status:\r\n");
        foreach(['pcntl', 'event', 'posix'] as $ext){
            Console::stdout("\t$ext: \t". (extension_loaded($ext) ? 'yes':'no')."\r\n");
        }
    }