?? waitpid.cc
字號:
#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{ for(int i=0; i<10; i++){ int cid=waitpid(-1,NULL,WNOHANG); if(cid<0) cout << "NO CHILD PROCESS!" << endl; else if(cid==0) cout << "CHILD PROCESS IS ALIVE!" << endl; else cout << "child:" << cid << "exited" << endl; cout << "PID=" << getpid() << endl; sleep(1); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -