Sends terminate signal to the process, allowing it to gracefully exit.

@param pid pid of the process to be sent SIGTERM
547902
public static void terminateProcess(String pid) {
    ShellCommandExecutor shexec = null;
    String errMsg = null;
    try {
      String[] args = { "kill", pid };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (IOException ioe) {
      // Do nothing, we log the exit code in the finally block.
      errMsg = ioe.getMessage();
    } finally {
      LOG.info("Killing process " + pid +
               " with SIGTERM. Exit code " + shexec.getExitCode() +
               (errMsg == null ? "" : " (" + errMsg + ")"));
    }
  }
308665
function terminate(control)
{
  if (control && control._process && typeof control._process.kill == 'function')
  {
    control._process._executioner_killRequested = true;
    control._process.kill();
    return true;
  }

  return false;
}
946074
function killRunningProcess(procName, callback) {
  var pidFilePath = pidDir + procName + '.pid';
  fs.readFile(pidFilePath, function(err, pidData) {
    if (err) {
      return callback(err);
    } else {
      return exec('kill ' + pidData.toString(), function(err, stdout, stderr) {
	return callback(null);
      });
    }
  });
}
1117481
protected function kill($signal, $pid)
    {
        $output = array();
        $message = exec(sprintf(($this->runtime['Default']['user'] !== $this->getProcessOwner() ? ('sudo -u '. escapeshellarg($this->runtime['Default']['user'])) . ' ' : "") . '/bin/kill -%s %s 2>&1', $signal, $pid), $output, $code);
        return array('code' => $code, 'message' => $message);
    }
466650
def kill_process(sig = 'TERM')
      content = IO.read(@options[:pid_file])
      pid = content.to_i
      fail("Invalid pid file content #{content.inspect}") if pid == 0
      begin
        Process.kill(sig, pid)
      rescue Errno::ESRCH => e
        fail("Could not find process with pid #{pid}")
      rescue Errno::EPERM => e
        fail("You don't have permissions to stop process #{pid}")
      rescue Exception => e
        fail(e.message)
      end
      true
    end
659173
public static boolean isPIDAlive(final int pid) throws IOException {
    final String ps = "ps";
    final String command[] = new String[] { ps, "-fp", pid + "" };
    final StringBuffer in = new StringBuffer();
    final Process process = Runtime.getRuntime().exec(command);
    
    InputStream inStream = process.getInputStream();
    InputStream errStream = process.getErrorStream();
    // wait for the process to complete.
    try {
      process.waitFor();
    } catch (final InterruptedException ignored) {
    }
    
    while (inStream.available() > 0) {
      in.append((char) inStream.read());
    }
    while (errStream.available() > 0) {
      in.append((char) errStream.read());
    }
    
    process.destroy();
    inStream.close();
    inStream = null;
    errStream.close();
    errStream = null;
    
    if (in.indexOf(pid + "") > 0)
      return true;
    return false;
  }
67260
public static function signalHandler($signo, $pid = null, $status = null)
    {
        switch ($signo) {
            case SIGTERM:
            case SIGINT:
                static::$_stop = true;
                break;
            case SIGCHLD:
                if (!$pid) {
                    $pid = pcntl_waitpid(-1, $status, WNOHANG);
                }
                while ($pid > 0) {
                    foreach (static::$workersPids as $workerUid => $workerPids) {
                        if (($key = array_search($pid, $workerPids)) !== false) {
                            unset(static::$workersPids[$workerUid][$key]);
                        }
                    }
                    $pid = pcntl_waitpid(-1, $status, WNOHANG);
                }
                break;
        }
    }
632514
public function childSignalHandler( $signo, $pid = null, $status = null )
    {
        // If no pid is provided, that means we're getting the signal from the system.  Let's figure out
        // which child process ended
        if( $pid === null )
        {
            $pid = pcntl_waitpid( -1, $status, WNOHANG );
        }

        //Make sure we get all of the exited children
        while( $pid > 0 )
        {
            if( $pid && isset( $this->currentJobs[$pid] ) )
            {
                $exitCode = pcntl_wexitstatus( $status );
                if ( $exitCode != 0 )
                {
                    $this->out->write( "Process #{$pid} of object version #".$this->currentJobs[$pid]->attribute( 'ezcontentobject_version_id' ) . " exited with status {$exitCode}" );
                    // this is required as the MySQL connection might be closed anytime by a fork
                    // this method is asynchronous, and might be triggered by any signal
                    // the only way is to use a dedicated DB connection, and close it afterwards
                    eZDB::setInstance( eZDB::instance( false, false, true ) );

                    $this->currentJobs[$pid]->reset();

                    eZDB::instance()->close();
                    eZDB::setInstance( null );
                }
                unset( $this->currentJobs[$pid] );
            }
            // A job has finished before the parent process could even note that it had been launched
            // Let's make note of it and handle it when the parent process is ready for it
            // echo "..... Adding $pid to the signal queue ..... \n";
            elseif( $pid )
            {
                $this->signalQueue[$pid] = $status;
            }
            $pid = pcntl_waitpid( -1, $status, WNOHANG );
        }
        return true;
    }
659377
def _killall(self, force=False):
        """"""
        for_termination = []

        for n, p in iteritems(self._processes):
            if 'returncode' not in p:
                for_termination.append(n)

        for n in for_termination:
            p = self._processes[n]
            signame = 'SIGKILL' if force else 'SIGTERM'
            self._system_print("sending %s to %s (pid %s)\n" %
                               (signame, n, p['pid']))
            if force:
                self._env.kill(p['pid'])
            else:
                self._env.terminate(p['pid'])
1018639
def _signal(self, sig, pid=None):
        
        log = self._params.get('log', self._discard)
        if pid is None:
            pids = self.get_pids()
        else:
            pids = [pid]
        for pid in pids:
            try:
                os.kill(pid, sig)
                log.debug("Signalled '%s' pid %d with %s", self._name, pid, utils.signame(sig))
            except Exception as e:
                log.warning("Failed to signal '%s' pid %d with %s -- %s", self._name, pid, utils.signame(sig), e)
918448
public function exitWorkerManager(int $sig, array $pid): void
    {
        $this->logger->debug('fork manager ['.$pid['pid'].'] exit with ['.$sig.']', [
            'category' => get_class($this),
        ]);

        pcntl_waitpid($pid['pid'], $status, WNOHANG | WUNTRACED);
        $this->cleanup(SIGTERM);
    }
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;
    }
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;
    }
74815
def process_kill(pid, sig=None):
    
    sig = sig or signal.SIGTERM
    os.kill(pid, sig)
314598
def _kill(self, kill_sig):
    """"""
    if self.pid:
      os.kill(self.pid, kill_sig)
945252
async function kill(pid) {
  try {
    process.kill(pid, 'SIGTERM')
  } catch (err) {
    if (err.code !== 'ESRCH') throw err
  }
}
1079559
public static function kill($pid, $signal = null)
    {
        if (is_null($signal)) {
            return \Swoole\Process::kill($pid);
        }
        return \Swoole\Process::kill($pid, $signal);
    }