Swoole\Process::kill ( int $pid [, int $signal_no ] )

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Process::kill ( int $pid [, int $signal_no ] )

Parameters

pid

the pid of child process

signo

the signal to send, the default is SIGTERM

Return

success

if sends signal successfully, it returns TRUE, otherwise it returns FALSE.

Description

Send signal to the child process.

Example

<?php
$child_num = 3;
$child_processes = [];
for($i = 1; $i <= $child_num; $i++)
{
    $process = new Swoole\Process(function($worker){
        echo "the pid of child process is " . $worker->pid . "\n";

        $worker->name("php child process");

        sleep(rand(20, 60));

    }, FALSE);

    $res = $process->useQueue(0, 2);

    $pid = $process->start();

    $child_processes[(string)$pid] = $process;
}

sleep(5);

foreach($child_processes as $pid => $child_process)
{
    $ret = Swoole\Process::kill($pid);
    var_dump($ret);

    $ret = Swoole\Process::wait();
    var_dump($ret);
}
Last updated on August 31, 2022