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 摘 要 随着人们对应用程序的要求越来越高,单进程应用在许多场合已不能满足人们的要求.编写多进 ...
随机推荐
- Linux 文件系统 -- 文件权限简介
一.文件权限 使用 ls -l 命令可以查看文件的具体属性: 如图所示,第一列所示告诉了用户一个文件的类型和权限信息: 1)第一个字符 "d",表明该文件是一个目录文件: 2)r ...
- IOS git 删除仓库 新建仓库 提交 合并 操作 码云
HDHaoShaoPengdeiMac:~ hdhaoshaopeng$ defaults write com.apple.finder AppleShowAllFiles TRUE HDHaoSha ...
- Python更新库
查看系统里过期的python库,可以用pip命令 [root@vnode33 sim-enb-sgi]# pip list #列出所有安装的库 Package Version ------------ ...
- Notes of Daily Scrum Meeting(11.15)
Notes of Daily Scrum Meeting(11.15) 今天周六我们的主要工作是把这周落下的一些工作补回来,这是写程序的最后阶段,准备进入测试阶段了,所以之前的工作 要补齐,今天大家的 ...
- 20172329 2018-2019-2 《Java软件结构与数据结构》实验二报告
20172329 2018-2019-2 <Java软件结构与数据结构>实验二报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 王文彬 学号:2017232 ...
- 删除一个数字之后数列gcd最大
★实验任务 顾名思义,互质序列是满足序列元素的 gcd 为 1 的序列.比如[1,2,3], [4,7,8],都是互质序列.[3,6,9]不是互质序列.现在并不要求你找出一个互质 序列,那样太简单了! ...
- 深入理解JAVA集合系列一:HashMap源码解读
初认HashMap 基于哈希表(即散列表)的Map接口的实现,此实现提供所有可选的映射操作,并允许使用null值和null键. HashMap继承于AbstractMap,实现了Map.Cloneab ...
- SQL Server 中几个有用的特殊函数
在SQL Server 的使用过程中,发现几个很有用,但不太常用(或细节不太清楚)的函数(存储过程): isnumeric,isdate,patindex,newid,collate,sp_execu ...
- java中的Serializable接口的作用
实现java.io.Serializable 接口的类是可序列化的.没有实现此接口的类将不能使它们的任一状态被序列化或逆序列化. 序列化类的所有子类本身都是可序列化的.这个序列化接口没有任何方法和域, ...
- leetcode动态规划
http://blog.csdn.net/u012162613/article/details/41428119