📄 666.c
字号:
#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#define MSGKEY 75struct msgform{ long mtype; char mtext [256]; double a,b,result; char opcode; int sender_pid;}msg;int msgqid;main(){ int i,pid,*pint; extern cleanup(); for(i=0;i<20;i++) signal(i,cleanup); msgqid =msgget(MSGKEY,0777|IPC_CREAT); for(;;) { msgrcv(msgqid,&msg,sizeof(struct msgform),1,0); switch(msg.opcode) {case'+': {msg.result=msg.a+msg.b;break;} case'-': {msg.result=msg.a-msg.b;break;} case'*': {msg.result=msg.a*msg.b;break;} case'/': {if(msg.b==0){printf("the msg.b is error");break;} else {msg.result=msg.a/msg.b; break;}} case'q': {printf("the opcode is error!");break;} } msg.mtype=msg.sender_pid; msg.sender_pid=getpid(); printf("server:receive from pid %d\n",msg.mtype); msgsnd(msgqid,&msg,sizeof(struct msgform),0);}}cleanup(){msgctl(msgqid ,IPC_RMID,0); exit();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -