array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } 111string(0) "" int(1) int(10) int(70) int(8640000) string(13) "likecs_art_db" array(1) { ["query"]=> array(1) { ["match_all"]=> object(stdClass)#28 (0) { } } } array(1) { ["createtime.keyword"]=> array(1) { ["order"]=> string(4) "desc" } } int(10) int(0) int(8640000) array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } Linux下利用fork()创建子进程并使父进程等待子进程结束 - 爱码网
int status;
pid_t t = fork();
if(t){
    waitpid(t, &status, 0);
}else{
    system("vi temp.txt");
    exit(0);
}
//父进程和子进程均执行完毕后继续执行下去
 
分析过程:
if 和 else 还是选择分支。 
主要的原因是,fork() 函数调用一次,返回两次。两次返回的区别是:子进程的返回值是0,父进程返回值为新子进程的进程ID。返回后,父进程执行waitpid(t, &status, 0)等待子进程结束,而子进程进入另一个分支执行system("vi temp.txt");exit(0);,父子间并不冲突,可以形容这段代码父进程与子进程都执行了一次判断。

相关文章: