資源簡介
使用系統調用pipe()建立一條管道線;兩個子進程P1和P2分別向管道各寫一句話:
Message from Child l!
Message from Child 2!
父進程從管道中讀出來自于兩個子進程的信息,顯示在屏幕上。
要求父進程先接收子進程P1發來的消息,然后再接收子進程P2發來的消息。
(站在巨人的肩膀上)
代碼片段和文件信息
//#include
//#include
#include
#define?sum?50
char?*message1?=?“Message?from?Child?1!“;
char?*message2?=?“Message?from?Child?2!“;
main()
{
int?p1p2;
int?a[2];
??????? char?b[50];
??????? pipe(a);
while?((p1=fork())==?-1);
?????? if(p1==0)
{ ??????
write(a[1]message1sum);???????
exit(0);
}else{
?????? while?((p2=fork())==?-1);
????????? if(p
評論
共有 條評論