service.c

来自「scounix编译通过,c/s完整实现」· C语言 代码 · 共 30 行

C
30
字号
/*./service.c*为请求进程服务的服务方进程*/#include <errno.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#define MSGKEY 3756main(){	struct msgbuf{		int mtype;		int mtext;	}buf;	int msqid, tmp;	msqid = msgget(MSGKEY, IPC_CREAT|0666);	for(;;){		/*接受请求*/		msgrcv(msqid, &buf, 256, 1, MSG_NOERROR);		tmp = buf.mtext;		printf("server receive a request from process %d\n", tmp);		buf.mtype = tmp ;		/*向请求进程发送应答消息*/		msgsnd(msqid, &buf, 1, 0);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?