内蒙古工业大学数据科学与应用学院
sprintf(pint,\msg.mtype=1000000;
msgsnd(msgqid,&msg,256,0); msgrcv(msgqid,&msg,256,pid,0); printf(\return 0; }
(2)服务器程序设计 #include
long mtype; char mtext[256]; }msg; int msgqid; void cleanup(); int main(){
int i,pid;
for(i=0;i<20;i++)
signal(i,cleanup);
int msgqid=msgget(MSGKEY,0777|IPC_CREAT);
pid=getpid();
printf(\
for(;;){
msgrcv(msgqid,&msg,256,1000000,0);
char*pint=msg.mtext;
printf(\ msg.mtype=atoi(msg.mtype);
*pint=pid;
printf(\sprintf(pint,\
第 页
内蒙古工业大学数据科学与应用学院
msgsnd(msgqid,&msg,256,0); }
void cleanup(){
}
msgctl(msgqid,IPC_RMID,0); exit(0);
}
return 0;
实验预期输出 1、进程的软中断通信【举例1】 Parent run! P1=4699 P2=4700 P2 run! Waiting begin! P1 run! Waiting begin! Signal stop! Waiting end! Child process 1 is killed by parent! Signal stop! Waiting end! Child process 2 is killed by parent! Parent process 2 is killed by parent! Parent process is killed! 1、进程的软中断通信【举例2】 Parent run! Process 2 run! Process 1 run! 2、进程的管道通信 Parent run! P1 run! P2 run! Child 2 process is sending a message! 3、进程的消息队列通信 Client:receive from pid2819 Server:receive from pid 32766 Server:receive from pid 32766 第 页
内蒙古工业大学数据科学与应用学院 Server:receive from pid 32766 Server:receive from pid 32766 Server:receive from pid 32766 Server:receive from pid 32766 Server:receive from pid 32766 Server:receive from pid 32766 Server:receive from pid 32766 Server:receive from pid 32766 ......
第 页