attempts to stop the thread
returns true on success and false otherwise

@param integer $_signal - SIGKILL/SIGTERM
@param boolean $_wait
162089
public function stop( $_signal = SIGKILL, $_wait = false ) {
		if( $this->isAlive() ) {
			posix_kill( $this->pid, $_signal );
			if( $_wait ) {
				pcntl_waitpid( $this->pid, $status = 0 );
			}
		}
	}
994587
protected function signalHandlerDefault($signal)
    {
        switch ($signal) {
            case SIGTERM:
            case SIGINT:
                // Check children
                while ($this->children) {
                    foreach ($this->children as $child) {
                        $ok = $child->kill(SIGINT);
                        /* EPERM */
                        if (posix_get_last_error() == 1) $ok = false;

                        if ($ok) {
                            // Emit exit
                            $child->emit('abort', $signal);
                            $child->shutdown($signal);
                            $this->clear($child);
                        }
                    }
                }
                $this->emit('abort', $signal);
                $this->shutdown($signal);
                exit;
                break;
        }
    }
258358
def kill signal = 'TERM', wait = false
      Process.kill signal, self.pid
      val = status if wait
      @stdin.close
      @stdout.close
      @stderr.close
      val
    end
555580
protected function sigwait($sec = 0, $nano = 0.3e9)
    {
        $siginfo = null;

        if (!function_exists('pcntl_sigtimedwait')) {
            $signo = $this->sigtimedwait(array_keys(static::$signals), $siginfo, $sec, $nano);
        } else {
            $signo = @\pcntl_sigtimedwait(array_keys(static::$signals), $siginfo, $sec, $nano);
        }

        if (is_bool($signo)) {
            return $signo;
        }

        if ($signo > 0) {
            $this->sighandler($signo);

            return true;
        }

        return false;
    }
419774
public static function killAndWait($pid, $signal = SIGTERM, $name = 'process', $waitTime = 30)
    {
        // do stop
        if (!self::kill($signal)) {
            Cli::stderr("Send stop signal to the $name(PID:$pid) failed!");

            return false;
        }

        // not wait, only send signal
        if ($waitTime <= 0) {
            Cli::stdout("The $name process stopped");

            return true;
        }

        $startTime = time();
        Cli::stdout('Stopping .', false);

        // wait exit
        while (true) {
            if (!self::isRunning($pid)) {
                break;
            }

            if (time() - $startTime > $waitTime) {
                Cli::stderr("Stop the $name(PID:$pid) failed(timeout)!");
                break;
            }

            Cli::stdout('.', false);
            sleep(1);
        }

        return true;
    }
514208
public function kill($signal = '', $waitForProcessToDisappear = false)
    {
        $pid = $this->getSupervisorPid();
        if (!empty($pid) && $this->isProcessRunning($pid)) {
            if (!empty($signal)) {
                $signal = sprintf('-%s', $signal);
            }

            $command = sprintf('kill %s %d', $signal, $pid);

            passthru($command);

            if ($waitForProcessToDisappear) {
                $this->wait();
            }
        }
    }
840583
public function startProcess($wait = true)
    {
        return $this->rpcClient->call('supervisor.startProcess', array($this->processGroup.':'.$this->processName, $wait));
    }
1030808
protected function _terminate($timeout = 10, $signal = /* SIGTERM */ 15) {
		foreach ($this->_getPidRecursive($this->getPid()) as $pid) {
			posix_kill($pid, $signal);
		}
		parent::stop($timeout, $signal);
	}
858561
def _wait_signal(signal, timeout=None):
    """"""
    # http://jdreaver.com/posts/2014-07-03-waiting-for-signals-pyside-pyqt.html
    loop = QEventLoop()
    signal.connect(loop.quit)

    yield

    if timeout is not None:
        QTimer.singleShot(timeout, loop.quit)
    loop.exec_()
1101121
def stop(self, silent=False):
        
        self.send_stop_signal(silent)
        self._lock.wait()
422236
private function waitUntilStopped(int $pid): void
    {
        $wait = 5000; // 5ms
        $timeout = 1000000; // 1 sec
        $elapsed = 0;
        while (posix_getpgid($pid) !== false) {
            usleep($wait);
            $elapsed += $wait;
            if ($elapsed > $timeout) {
                throw new \Exception('Timeout while waiting for PHP-FPM to stop');
            }
        }
    }
393487
public function terminateProcess(Process $process, $signal = SIGKILL)
    {
        $this->posix->kill($process->getId(), $signal);
        if (false === $process->isMaster()) {
            $this->getMaster()->removeChild($process);
        }

        return $this;
    }
745291
public function kill(int $pid, bool $wait = false): bool
    {
        return $this->process->kill($pid, $wait);
    }
954281
private function killKeepTransactionAlive() {
        if ($this->txProcPid > 0) {
            posix_kill($this->txProcPid, \SIGKILL);
            $status          = null;
            pcntl_wait($status);
            $this->txProcPid = null;
        }
        if ($this->txProc) {
            $this->txProc = null;
        }
    }
791147
public static function term($pid, $lagger_timeout = 0, $signal = SIGTERM) {

        $kill_time = time() + $lagger_timeout;

        // $term = posix_kill($pid, $signal);
        $term = self::signal($pid, $signal);

        while ( time() < $kill_time ) {

            if ( !self::isRunning($pid) ) return $term;
            usleep(20000);

        }

        return self::kill($pid);

    }
720901
public function signalReceived($signal)
	{
		if (!$this->tryCall($this->formatSignalMethod($signal), $this->params)) {
			$class = get_class($this);
			throw new BadSignalException("There is no handler for signal '$signal' in class $class.");
		}
	}
988838
private static function _makeWaiter($max_wait)
    {
        $waited = 0;
        $sleep  = 1000;

        return function () use ($max_wait, &$waited, &$sleep) {
            if ($max_wait < $waited) {
                return false;
            }

            usleep($sleep);
            $waited += $sleep;
            $sleep *= 2;

            return true;
        };
    }