QNX下进程间通信
https://blog.csdn.net/dh314552189/article/details/87879016
server.cpp
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/dispatch.h>
#include <string.h> #define ATTACH_POINT "percent" #define VERSION "V1.2.0" int rcvid = ; struct version_message
{
int type;
char data[];
}; int main(int argc, char *argv[]) {
name_attach_t *attach;
struct version_message rmsg;
struct version_message smsg;
int rcvid; /* Create a local name (/dev/name/local/...) */
if ((attach = name_attach(NULL, ATTACH_POINT, )) == NULL) {
printf("name_attach error!\n");
return EXIT_FAILURE;
} while()
{
rcvid = MsgReceive(attach->chid, &rmsg, sizeof(rmsg), NULL);
if(rcvid > )
{
/* name_open() sends a connect message, must EOK this */
if (rmsg.type == _IO_CONNECT ) {
printf("connect received!\n");
MsgReply( rcvid, EOK, NULL, );
continue;
} /* Some other QNX IO message was received; reject it */
if (rmsg.type > _IO_BASE && rmsg.type <= _IO_MAX ) {
printf("wrong msg type received!\n");
MsgError( rcvid, ENOSYS );
continue;
} /* reply the bsp version */ if(0x1 == rmsg.type)
{
printf("version request received!\n");
printf("version request received data = %s \n",rmsg.data);
MsgReply( rcvid, EOK, NULL, );
}
}
else if( == rcvid)
{
printf("pulse msg received!\n");
}
} /* Remove the name from the space */
name_detach(attach, ); return EXIT_SUCCESS;
}
client.cpp
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mman.h> #include <sys/iofunc.h>
#include <sys/dispatch.h>
#define ATTACH_POINT "percent" struct version_message
{
int type;
char data[];
}; int main(int argc, char *argv[]) {
struct version_message smsg;
struct version_message rmsg;
int server_coid;
int rcvid; if ((server_coid = name_open(ATTACH_POINT, )) == -) {
printf("name_open error!");
return EXIT_FAILURE;
} /* We would have pre-defined data to stuff here */
smsg.type = 0x01;
strcpy(smsg.data,"ygy"); /* Do whatever work you wanted with server connection */
printf("Client sending %d \n", smsg.type);
if (MsgSend(server_coid, &smsg, sizeof(smsg), &rmsg, sizeof(rmsg)) == -) {
printf("MsgSend error!");
name_close(server_coid);
return EXIT_FAILURE;
} /* Close the connection */
name_close(server_coid);
}
cmakelist
# . Project Name project(test.IPC) # . Project Env (Include/Lib Path, C/CXX/LD FLAGS) include_directories(
) link_directories(
${COMMONAPI_LIBDIR}
) # . Project Build #set(TEST_NAME "svp.test.client")
set(TEST_NAME "svp.test.server")
set(TEST_SRC_FILES # client.cpp
server.cpp
) add_executable(${TEST_NAME} ${TEST_SRC_FILES}) target_link_libraries(${TEST_NAME}
svp_basic ${upgrade_CAPI_GEN_LIB}
CommonAPI m ) # . Project Install install(TARGETS ${TEST_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
其实是有fifo也是可行的。
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/dispatch.h>
#include <string.h> #include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> int main(int argc, char *argv[]) { if (access("/aaa", F_OK) == -) {
if (mkfifo("/aaa", S_IRUSR|S_IWUSR) != ) {
printf("mkfifo error!\n");
return ;
}
}
int fd = open("/aaa",O_WRONLY);
if (fd == -) {
printf("open error!\n");
return ;
}
while(){
write(fd, "ygy\n", );
sleep();
} return EXIT_SUCCESS;
}
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mman.h> #include <sys/iofunc.h>
#include <sys/dispatch.h> #include <unistd.h>
#include <fcntl.h> int main(int argc, char *argv[]) { int res = ;
int fd = open("/aaa", O_RDONLY);
char buffer[];
if (fd != -) {
printf("open ok\n");
while ((res = read(fd, buffer, )) > ) {
printf(">>>>>>>>>>>%s", buffer);
}
} }

QNX下进程间通信的更多相关文章
- 浅析Linux下进程间通信:共享内存
浅析Linux下进程间通信:共享内存 共享内存允许两个或多个进程共享一给定的存储区.因为数据不需要在客户进程和服务器进程之间复制,所以它是最快的一种IPC.使用共享内存要注意的是,多个进程之间对一给定 ...
- WINCE下进程间通信(二)
WINCE下进程间通信(二) 接着前面的文章<WINCE下进程间通信(一)>,现在介绍进程间通信的另一种方法. 三.管道(消息队列) WINCE并不支持类似于PC机上匿名管道.命名管道的通 ...
- WINCE下进程间通信(一)
WINCE下进程间通信(一) 在WINCE开发中经常需要在不同的进程之间传递.共享数据,总结了一下,WINCE下进程间通信常用的方式有:Windows消息,共享内存,socket通信,管道,全局原子, ...
- Linux下进程间通信的六种机制详解
linux下进程间通信的几种主要手段: 1.管道(Pipe)及有名管道(named pipe):管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具 ...
- Windows下进程间通信及数据共享
进程是装入内存并准备执行的程序,每个进程都有私有的虚拟地址空间,由代码.数据以及它可利用的系统资源(如文件.管道等)组成. 多进程/多线程是Windows操作系统的一个基本特征.Microsoft W ...
- Linux下进程间通信--消息队列
消息队列的定义遍地都是,不想移驾,请看下文: 一.定义: 消息队列提供了一种从一个进程向另一个进程发送一个数据块的方法. 每个数据块都被认 为是有一个类型,接收者进程接收的数据块可以有不同的类型值.我 ...
- windows下进程间通信与线程间通信
进程间通信: 1.文件映射(Memory-Mapped Files) 文件映射(Memory-Mapped Files)能使进程把文件内容当作进程地址区间一块内存那样来对待.因此,进程不必使用文件I/ ...
- windows下进程间通信(转)
摘 要 随着人们对应用程序的要求越来越高,单进程应用在许多场合已不能满足人们的要求.编写多进程/多线程程序成为现代程序设计的一个重要特点,在多进程程序设计中,进程间的通信是不可避免的.Microsof ...
- windows下进程间通信的(13种方法)
转自:http://blog.csdn.NET/shiqz/article/details/5862936 摘 要 随着人们对应用程序的要求越来越高,单进程应用在许多场合已不能满足人们的要求.编写多进 ...
随机推荐
- 1.Python3.6环境部署
标题:Python3.6环境部署文档 作者:刘耀 内容 Linux部署Python3.6环境 Mac部署Python3.6环境 Window10部署Python3.6环境 Pycharm安装 1. L ...
- Python图形界面开发—wxPython库的布局管理及页面切换
前言 wxPython是基于Python的跨平台GUI扩展库,对wxWidgets( C++ 编写)封装实现.GUI程序的开发中界面布局是很重要的一个部分,合理的页面布局能够给予用户良好使用体验.虽然 ...
- “秒杀”问题的数据库和SQL设计【转载】
“秒杀”问题的数据库和SQL设计 APRIL 21ST, 2015 问题的来源 完全不考虑一致性的方案 表结构 方案 存在的问题 保证单用户不会重复购买 解决超卖问题 方案 优化 提高性能了 鱼与熊掌 ...
- LeetCode 455. Assign Cookies (C++)
题目: Assume you are an awesome parent and want to give your children some cookies. But, you should gi ...
- 微信小程序——音阶练耳 宣传页面
音阶练耳是什么? 音阶练耳小程序是一款听音练习音阶,拥有简介界面的交互式小程序,以虚拟钢琴为辅助乐器,应用于日常练习,涵盖了五个八度内26种调式.以及下行中的所有调式与和声小调式的衍生,提高辨认音阶的 ...
- Daily Scrum (2015/11/8)
由于编译大作业临近deadline以及各项选修课即将结课,虽然PM强调软工任务也很紧迫,但是大多数成员表示今天想请假一天.符美潇今天把自己所负责的数据库编码部分和谢金洛的UI进行了对接.在测试过程中发 ...
- 作业1-MathExam
MathExam 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 10 30 • Estim ...
- 2017-2018-2 1723 『Java程序设计』课程 结对编程练习-四则运算-中坚阶段
2017-2018-2 1723 『Java程序设计』课程 结对编程练习-四则运算-中坚阶段 如今的编写,进入了一段时间的中坚阶段,小伙伴的思路虽然很一致,但是总是存在着一定问题,这就造成了我们中坚阶 ...
- python learning IO.py
f = open('test.txt', 'r') # 'r' 表示只读 s = f.read() # 调用read()方法可以一次读取文件的全部内容,Python把内容读到内存,用一个str对象表示 ...
- HighCharts点击柱形或饼块等加URL或Click事件
我们在做图表的时候,有时候需要在单个数据上加链接或点击事件,是在plotOptions里的events里设置的: 如下代码: plotOptions: { pie: { cursor: 'pointe ...