⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waitpid.cc

📁 达内IT培训Unix C++第二天源码 是入门Unix 下C++编程的好东西
💻 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 + -