wait(0); read(fd[0],inpipe,50); printf(\ exit(0); } } } 〈运行结果〉 延迟5秒后显示: child1 process is sending message! 再延迟5秒: child2 process is sending message! (2)消息的创建,发送和接收 21 / 27
#include
息队列*/ } exit(0); } void SERVER( ) { msgqid=msgget(MSGKEY,0777|IPC_CREAT); /*由关键字获得消息队列*/ do { msgrcv(msgqid,&msg,1030,0,0); /*从队列msgid接受消息msg*/ printf(\ }while(msg.mtype!=1); /*消息类型为1时,释放队列*/ msgctl(msgqid, IPC_RMID,0); } main() { if(fork()) { 23 / 27
SERVER(); wait(0); } else CLIENT( ); } <运行结果> 。。。 24 / 27
五.设计流程图 25 / 27