swoole创建进程

<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 2020/4/23
 * Time: 21:57
 */

use Swoole\Process;

echo getmypid().PHP_EOL;
cli_set_process_title("mymain");

$process = new Process(function ()  {
    cli_set_process_title("mychild");
    echo 子进程 # . getmypid()  . PHP_EOL;
});
$process->start();

Process::wait(true);

while(true)
{
    sleep(1);
}

如果没有这一行回收子进程 ,那么子进程不会回收 直到主进程执行完 

[root@localhost wang]# php index.php 
4692
子进程 #4693
[root@localhost wang]# ps -ef|grep 4692
root      4692  8091  0 23:14 pts/0    00:00:00 mymain
root      4693  4692  0 23:14 pts/0    00:00:00 [php] <defunct>
root      4701  4652  0 23:15 pts/1    00:00:00 grep --color=auto 4692
[root@localhost wang]# 

 

如果加了wait

[root@localhost wang]# php index.php 
4702
子进程 #4703
[root@localhost wang]# ps -ef|grep 4702
root      4702  8091  0 23:15 pts/0    00:00:00 mymain
root      4707  4652  0 23:15 pts/1    00:00:00 grep --color=auto 4702

 

cli_set_process_title 设置进程的标题 

  

  

swoole创建进程

上一篇:Mac下Idea快捷键操作(使用/修改)


下一篇:CreateRemoteThread方式实现进程注入