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

📄 msgwrite.c

📁 《Linux程序设计权威指南》源代码
💻 C
字号:
	/* File: msgwrite.c */	#include <stdio.h>	#include <stdlib.h>	#include <sys/types.h>	#include <sys/ipc.h>	#include <sys/msg.h>	#include "defs.h"	int main(int argc, char* argv[])	{		int queue_id;		struct msgbuf* msg;		int i;		int rc;		//建立消息队列, 只有相同用户可以使用		queue_id = msgget(QUEUE_ID, IPC_CREAT | IPC_EXCL | 0600);		if (queue_id == -1) {			perror("main: msgget");			exit(1);		}		printf("message queue created, queue id '%d'.\n", queue_id);		msg =(struct msgbuf*)malloc(sizeof(struct msgbuf)+MAX_MSG_SIZE);		//发送数据		for (i=1; i <= NUM_MESSAGES; i++) {			msg->mtype = (i % 3) + 1;			sprintf(msg->mtext, "hello world - %d", i);			rc = msgsnd(queue_id, msg, strlen(msg->mtext)+1, 0);			if (rc == -1) {				perror("main: msgsnd");				exit(1);			}		}		free(msg);    		printf("generated %d messages, exiting.\n", NUM_MESSAGES);		return 0;	}

⌨️ 快捷键说明

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