17 消息队列2
来源:互联网 发布:小程序 post php接收 编辑:程序博客网 时间:2024/05/20 01:46
1. 同一进程间发送接收信息示例,熟练使用几个函数。
2. 示例,创建消息队列 --> 写队列,类型100,--> 第一次读队列 --> 第二次读队列(阻塞) --> 删除队列:
#include "sys/types.h"#include "sys/msg.h"#include "signal.h"#include "unistd.h"#include "stdio.h"#include "stdlib.h"#include "string.h"struct msgbuf{ long type; char voltage[124]; char ID[4];};int main(){ int msgid; int readret; struct msgbuf sendbuf,recvbuf; msgid=msgget(IPC_PRIVATE,0777); if(msgid <0) {printf("creat message queue failure\n");return -1; } printf("creat message queue sucess msgid=%d\n",msgid); system("ipcs -q"); //init sendbuf sendbuf.type=100; printf("please input message:\n"); fgets(sendbuf.voltage,124,stdin); //start write message to message queue msgsnd(msgid,(void *)&sendbuf,strlen(sendbuf.voltage),0); //start read message from message queue memset(recvbuf.voltage,0,124); readret=msgrcv(msgid,(void *)&recvbuf,124,100,0); printf("recv:%s",recvbuf.voltage); printf("readret=%d\n",readret); //second read message queue msgrcv(msgid,(void *)&recvbuf,124,100,0); printf("second read after\n"); //delete message queue msgctl(msgid,IPC_RMID,NULL); system("ipcs -q"); return 0;}
alex@alex-VirtualBox:~/Share/process/seventeen$ gcc msg.calex@alex-VirtualBox:~/Share/process/seventeen$ ./a.outcreat message queue sucess msgid=32768------ Message Queues --------key msqid owner perms used-bytes messages0x00000000 32768 alex 777 0 0please input message:hellorecv:helloreadret=6
0 0
- 17 消息队列2
- 消息队列-2
- 消息队列2
- Kafka#2:消息队列
- 消息队列2
- 消息队列(2):消息存哪里了?
- 3.2.2 队列消息和非队列消息
- RabbitMQ消息队列(2):工作队列之消息分发机制
- 3.2.2 队列消息和非队列消息
- 分布式消息队列(2)
- 2-19 消息队列通信
- 消息队列
- 消息队列
- 消息队列
- 消息队列
- 消息队列
- 消息队列
- 消息队列
- tensorFlow 教程
- View的事件分发机制
- ml note
- 【J2EE】Cookie
- Hibernate整合连接池
- 17 消息队列2
- View基础知识
- .Net多线程编程—使用Visual Studio 2012进行调试
- 解决React Native中ListView控件在ios上不能滑动的问题
- 大端字节序和小端字节序
- java网络爬虫开发笔记(3)
- mysql同时更新多条记录的同一个字段
- java
- 2016年个人总结社区版