4、進程間通信-消息隊列IPC

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章