zoukankan      html  css  js  c++  java
  • pcntl_fork() 函数

    https://php.golaravel.com/function.pcntl-fork.html
    pcntl_fork — 在当前进程当前位置产生分支(子进程)。
    译注:fork是创建了一个子进程,父进程和子进程 都从fork的位置开始向下继续执行,不同的是父进程执行过程中,得到的fork返回值为子进程 号,而子进程得到的是0。

    for ($i = 0; $i < 3; $i++) {
        $pid = pcntl_fork();
        if ($pid > 0) {
            echo '父进程空间:'. $i .'-- 子进程ID:'. $pid. '-- 当前进程ID:'. posix_getpid() , "
    ";
        } else if ($pid == 0) {
            echo '子进程空间:'. $i .'-- 子进程ID:'. $pid. '-- 当前进程ID:'. posix_getpid(), "
    ";
        } else {
            echo '错误了', $pid, "
    ";
        }
    }
    sleep(30);
    
    root@31e710224d20:/var/www/html# ps aux | grep pcntl
    root       128  0.5  1.4 203620 28780 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       129  0.0  0.4 203620  8564 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       130  0.0  0.3 203620  7792 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       131  0.0  0.3 203620  7792 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       132  0.0  0.4 203620  8468 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       133  0.0  0.4 203620  8468 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       134  0.0  0.4 203620  8468 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       135  0.0  0.4 203620  8468 pts/0    S+   01:07   0:00 php swoole/server/pcntl.php
    root       137  0.0  0.0  11112   980 pts/1    S+   01:07   0:00 grep pcntl
    
    php swoole/server/pcntl.php
    父进程空间:0-- 子进程ID:129-- 当前进程ID:128
    子进程空间:0-- 子进程ID:0-- 当前进程ID:129
    父进程空间:1-- 子进程ID:130-- 当前进程ID:128
    父进程空间:1-- 子进程ID:131-- 当前进程ID:129
    子进程空间:1-- 子进程ID:0-- 当前进程ID:131
    子进程空间:1-- 子进程ID:0-- 当前进程ID:130
    父进程空间:2-- 子进程ID:132-- 当前进程ID:128
    子进程空间:2-- 子进程ID:0-- 当前进程ID:132
    父进程空间:2-- 子进程ID:134-- 当前进程ID:130
    父进程空间:2-- 子进程ID:133-- 当前进程ID:131
    子进程空间:2-- 子进程ID:0-- 当前进程ID:133
    父进程空间:2-- 子进程ID:135-- 当前进程ID:129
    子进程空间:2-- 子进程ID:0-- 当前进程ID:134
    子进程空间:2-- 子进程ID:0-- 当前进程ID:135
    
  • 相关阅读:
    牛客寒假算法基础集训营1 C 小a与星际探索(思维+异或)
    牛客寒假算法基础集训营4 E Applese 涂颜色
    Python的range()函数用法
    R语言读取XML数据
    R语言如何读取.csv文件
    反转链表
    HashSet HashTable HashMap 区别
    输入两个整数 n 和 m,从数列1,2,3.......n 中随意取几个数,使其和等于 m ,要求将其中所有的可能组合列出来.
    Activity生命周期之我见
    左旋转字符串
  • 原文地址:https://www.cnblogs.com/smallyi/p/13894874.html
Copyright © 2011-2022 走看看