⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client1.c

📁 源码包中是我在学习Linux进程间通信时所写的关于五种通信方式(管道
💻 C
字号:
/* client1 */#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#include <string.h>#include <unistd.h>#include <signal.h>#define KEY_MSG         0x101#define MSGSIZE         128int main(){		int     msgid;        struct  msgbuf        {                long    mtype;		int	subtype;                char    mtext[MSGSIZE];        }bufin, bufout;	msgid = msgget( KEY_MSG, 0666 );		/* open message queue created by server */	if( fork() == 0 )	{		printf( "send message to client2 :" );		while(1)		{			fgets( bufout.mtext, MSGSIZE, stdin );			bufout.mtype = 1L;				bufout.subtype = 2;			msgsnd( msgid, &bufout, MSGSIZE+4, 0 );		}	}	else	{		while(1)		{			msgrcv( msgid, &bufin, MSGSIZE+4, 2L, 0 );			if( bufin.mtext[0] == 'x' || bufin.mtext[0] == 'X' )                	{				kill( fork(), SIGINT );                        	break;                	}			printf("receive message from client2 :%s", bufin.mtext );		}	}}

⌨️ 快捷键说明

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