1、创建一个消息队列,然后使用msgctl函数读取相关信息,单进程
code:
结果:
root@ubuntu:/code/chap9# ./run1
res is 0
buf.msgmax=8192
rev msg:hello world
2、使用消息队列实现实时通信(注:阻塞的)。可以考虑实现双向的基于类型的、非阻塞方式的双向数据传递
code:
发送端代码:
接受端代码:
结果:
发送端:
root@ubuntu:/code/chap9# ./run2
enter
Jason
enter
Liu
enter
end
接受端:
root@ubuntu:/code/chap9# ./run2_o
rcv:Jason
rcv:Liu
rcv:end