public function safe_kill($pid, $signal, $log_message = '', $log_level = self::LOG_LEVEL_INFO)
	{
		if (!array_key_exists($pid, $this->forked_children))
		{
			return false;
		}

		$stat_pid_file = '/proc/' . $pid . '/stat';
		if (!file_exists($stat_pid_file))
		{
			$this->log('Unable to find info for PID ' . $pid . ' from ' . $stat_pid_file, self::LOG_LEVEL_DEBUG);
			return false;
		}

		$stat_pid_info = file_get_contents($stat_pid_file);
		if ($stat_pid_info === false)
		{
			$this->log('Unable to get info for PID ' . $pid, self::LOG_LEVEL_DEBUG);
			return false;
		}

		$stat_pid_info = explode(' ', $stat_pid_info);
		if (!array_key_exists(3, $stat_pid_info))
		{
			$this->log('Unable to find parent PID for PID ' . $pid, self::LOG_LEVEL_DEBUG);
			return false;
		}

		// the parent pid is the fourth entry in /proc/PID/stat
		if ($stat_pid_info[3] == getmypid())
		{
			if ($log_message)
			{
				$this->log($log_message, $log_level);
			}

			posix_kill($pid, $signal);
			return true;
		}

		$this->log('Failed to kill PID ' . $pid . ' with signal ' . $signal, self::LOG_LEVEL_WARN);
		return false;
	}
public function safe_kill($pid, $signal, $log_message = '', $log_level = self::LOG_LEVEL_INFO)
	{
		if (!array_key_exists($pid, $this->forked_children))
		{
			return false;
		}

		$stat_pid_file = '/proc/' . $pid . '/stat';
		if (!file_exists($stat_pid_file))
		{
			$this->log('Unable to find info for PID ' . $pid . ' from ' . $stat_pid_file, self::LOG_LEVEL_DEBUG);
			return false;
		}

		$stat_pid_info = file_get_contents($stat_pid_file);
		if ($stat_pid_info === false)
		{
			$this->log('Unable to get info for PID ' . $pid, self::LOG_LEVEL_DEBUG);
			return false;
		}

		$stat_pid_info = explode(' ', $stat_pid_info);
		if (!array_key_exists(3, $stat_pid_info))
		{
			$this->log('Unable to find parent PID for PID ' . $pid, self::LOG_LEVEL_DEBUG);
			return false;
		}

		// the parent pid is the fourth entry in /proc/PID/stat
		if ($stat_pid_info[3] == getmypid())
		{
			if ($log_message)
			{
				$this->log($log_message, $log_level);
			}

			posix_kill($pid, $signal);
			return true;
		}

		$this->log('Failed to kill PID ' . $pid . ' with signal ' . $signal, self::LOG_LEVEL_WARN);
		return false;
	}
public function safe_kill ( $ pid , $ signal , $ log_message = '' , $ log_level = self :: LOG_LEVEL_INFO ) { if ( ! array_key_exists ( $ pid , $ this -> forked_children ) ) { return false ; } $ stat_pid_file = '/proc/' . $ pid . '/stat' ; if ( ! file_exists ( $ stat_pid_file ) ) { $ this -> log ( 'Unable to find info for PID ' . $ pid . ' from ' . $ stat_pid_file , self :: LOG_LEVEL_DEBUG ) ; return false ; } $ stat_pid_info = file_get_contents ( $ stat_pid_file ) ; if ( $ stat_pid_info === false ) { $ this -> log ( 'Unable to get info for PID ' . $ pid , self :: LOG_LEVEL_DEBUG ) ; return false ; } $ stat_pid_info = explode ( ' ' , $ stat_pid_info ) ; if ( ! array_key_exists ( 3 , $ stat_pid_info ) ) { $ this -> log ( 'Unable to find parent PID for PID ' . $ pid , self :: LOG_LEVEL_DEBUG ) ; return false ; } // the parent pid is the fourth entry in /proc/PID/stat if ( $ stat_pid_info [ 3 ] == getmypid ( ) ) { if ( $ log_message ) { $ this -> log ( $ log_message , $ log_level ) ; } posix_kill ( $ pid , $ signal ) ; return true ; } $ this -> log ( 'Failed to kill PID ' . $ pid . ' with signal ' . $ signal , self :: LOG_LEVEL_WARN ) ; return false ; }
Try to kill a given process and make sure it is safe to kill

@param int    $pid         The PID to check if it is our child.
@param int    $signal      The kill signal to send to the given pid if possible.
@param string $log_message The message to log out upon success.
@param int    $log_level   The level at which to display the log_message.
@return bool true on successful kill, false if not our child or not able to kill
Try to kill a given process and make sure it is safe to kill