C 消息队列实现通信
来源:互联网 发布:淘宝会员抓取系统 编辑:程序博客网 时间:2024/05/19 19:13
sendmsg:
/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
#include <sys/msg.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdlib.h>
#include <string.h>
struct msg
{
long msg_types;
char msg_buf[512];
};
int main()
{
int qid;
int pid;
int len;
struct msg pmsg;
pmsg.msg_types = getpid();
sprintf(pmsg.msg_buf,"hello! this is %d \n\0",getpid());
len = strlen(pmsg.msg_buf);
qid = msgget(IPC_PRIVATE,IPC_CREAT|0666);
//qid = msgget(0,IPC_CREAT|0666);
msgsnd(qid,&pmsg,len,0);
printf("succesfully send a message to queue:%d\n",qid);
//system("ipcs -q");
return 0;
}
recmsg:
/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
#include <sys/msg.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdlib.h>
#define BUFSZ 4096
struct msg
{
long msg_types;
char msg_buf[512];
};
int main(int argc,char ** argv)
{
int qid;
int len;
struct msg pmsg;
if(argc != 2)
{
perror("argc");
}
qid = atoi(argv[1]);
len = msgrcv(qid,&pmsg,BUFSZ,0,0);
if(len > 0)
{
pmsg.msg_buf[len] = '\0';
printf("qid %d\n",qid);
printf("msg type %d\n",pmsg.msg_types);
printf("msg text %s\n",pmsg.msg_buf);
}
else if( len == 0)
{
printf("no message!\n");
}
else
{
perror("msgrcv\n");
}
//system("ipcs -q");
return 0;
}
- C 消息队列实现通信
- 消息队列实现通信
- VxWorks中基于消息队列实现C/S通信
- [Linux C编程]消息队列实现同时通信
- linux c之通过消息队列实现进程通信
- Linux C消息队列实现进程间通信
- linux 消息队列实现通信
- 实现基于VxWorks的消息队列通信机制的C/S通信
- linux C-(进程间通信 消息队列)
- 基于消息队列的C/S通信
- 基于消息队列的C/S通信
- C语言消息队列通信函数描述
- C实现消息队列Queue
- 【C语言】【unix c】两个进程通过消息队列实现进程间的通信
- 消息队列实现进程间通信
- Linux进程通信---消息队列 代码实现
- 进程间通信:消息队列(代码实现)
- 进程间通信:消息队列(代码实现)
- html5表单新增3个属性
- 水塘抽样
- python模拟浏览器访问网站
- XP电脑桌面图标文字带上颜色不透明 解决办法
- 工厂设计模式
- C 消息队列实现通信
- 润乾报表内置hsql的端口占用问题
- Android Path 解析
- mysql中数据库的备份与恢复
- Linux下段错误 coredump设置
- 数据库事务(Transaction)的ACID特性解释
- JavaWeb工作原理
- 杨辉三角
- Google官方支持的MVVM架构框架Data Binding使用入门