Home > Backend Development > PHP Tutorial > 【PHP】PHP进程系列-学习篇(1)

【PHP】PHP进程系列-学习篇(1)

WBOY
Release: 2016-06-23 13:06:05
Original
1012 people have browsed it

    $nowPID=getmypid(); //获取当前主进程的PID

    $PID=pcntl_fork();//创建一个子进程  创建成功时。PID=0(子进程)  PID>0(父进程)

    if($PID ==-1){
        die('子进程创建失败');
    }
    else if($PID){
        echo "【父进程】我的PID是:".$nowPID.",子进程PID:".$PID."
";

    }else{
        $forkPID=getmypid(); //获取当前主进程的PID
        file_put_contents("子进程任务.txt", "【子进程】我的PID是:".$forkPID.",父进程PID:".$nowPID); //子进程会执行自己的任务
    }


    file_put_contents(getmypid().".txt", "进程"); //子进程会执行自己的任务
    exit('进程结束');

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template