消息隊列 是進程間通信的一種方式,它不像管道那樣是基於字節流,而是基於消息。
也就是說,消息隊列不一定是先進先出了。
這次我用消息隊列實現一個簡單的進程間通信程序,讓兩個進程server和client進行通信
(由於要准備學校的期末考試,先貼代碼和運行結果,原理分析之後補上)
程序結構:

Makefile:

comm.h & comm.c:

msg_server.h & msg_client.h:

msg_server.c:


msg_client.c


運行結果:
先啟動服務器:
(錯誤13,沒有權限,所以開root模式)

再啟動客戶端:
(再開啟一個終端,貌似還是需要root模式)
