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

📄 msg1.c

📁 本文件介绍了unix内核的c源代码
💻 C
字号:
#include <sys/msg.h>#include <sys/types.h>#include <sys/ipc.h>#include <stdio.h>#include <sys/errno.h>extern int errno;struct mymsgbuf 			/* 定义消息结构 */{	long	mtype;   		/* 消息类型 */	char	ctext[100];		/* 消息数据 */};void main(){	struct mymsgbuf buf;	/* 申请消息缓冲 */	int msid;	/* 打开(或创建)消息队列 */	if ((msid = msgget(0x1234, 0666|IPC_CREAT)) < 0) 	{		fprintf(stderr, "open msg %X failed.\n", 0x1234);		return ;	}	while(strncmp(buf.ctext, "exit", 4))	{		memset(&buf, 0, sizeof(buf));		fprintf(stderr, "Please input:");		/* 从键盘输入消息数据内容 */		fgets(buf.ctext, sizeof(buf.ctext), stdin);		/* 设置消息类型 */		buf.mtype = getpid();				/* 发送消息 */		while ((msgsnd(msid, &buf, strlen(buf.ctext), 0)) < 0)		{			if (errno == EINTR) continue;			return;		}	}}

⌨️ 快捷键说明

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