wait.cc
来自「达内IT培训Unix C++第二天源码 是入门Unix 下C++编程的好东西」· CC 代码 · 共 29 行
CC
29 行
#include <iostream>using namespace std;#include <unistd.h>#include <sys/wait.h>int main(){ int ret = fork(); if(ret<0){ cout << "error in fork!" << endl; return -1; } if(ret==0){ for(int i=0; i<5; i++){ cout << "pid=" << getpid() << ", my parent:" << getppid() << endl; sleep(1); } } else{ int pid=wait(NULL); cout << "wait return:" << pid<<endl; for(int i=0; i<10; i++){ cout << "PID=" << getpid() << endl; sleep(1); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?