熟女俱乐部五十路二区av,又爽又黄禁片视频1000免费,国产卡一卡二卡三无线乱码新区,中文无码一区二区不卡αv,中文在线中文a

新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 進程間通信之:消息隊列

進程間通信之:消息隊列

作者: 時間:2013-09-13 來源:網絡 收藏

本文引用地址:http://www.bjwjmy.cn/article/257123.htm

以下是接收端的代碼:

/*msgrcv.c*/

#includesys/types.h>

#includesys/ipc.h>

#includesys/msg.h>

#includestdio.h>

#includestdlib.h>

#includeunistd.h>

#includestring.h>

#defineBUFFER_SIZE512

structmessage

{

longmsg_type;

charmsg_text[BUFFER_SIZE];

};

intmain()

{

intqid;

key_tkey;

structmessagemsg;

/*根據不同的路徑和關鍵字產生標準的key*/

if((key=ftok(.,'a'))==-1)

{

perror(ftok);

exit(1);

}

/*創(chuàng)建*/

if((qid=(key,IPC_CREAT|0666))==-1)

{

perror();

exit(1);

}

printf(Openqueue%dn,qid);

do

{

/*讀取*/

memset(msg.msg_text,0,BUFFER_SIZE);

if(msgrcv(qid,(void*)msg,BUFFER_SIZE,0,0)0)

{

perror(msgrcv);

exit(1);

}

printf(Themessagefromprocess%d:%s,msg.msg_type,msg.msg_text);

}while(strncmp(msg.msg_text,quit,4));

/*從系統(tǒng)內核中移走消息隊列*/

if((msgctl(qid,IPC_RMID,NULL))0)

{

perror(msgctl);

exit(1);

}

exit(0);

}

以下是程序的運行結果。輸入“quit”則兩個進程都將結束。

$./msgsnd

Openqueue327680

Entersomemessagetothequeue:firstmessage

Entersomemessagetothequeue:secondmessage

Entersomemessagetothequeue:quit

$./msgrcv

Openqueue327680

Themessagefromprocess6072:firstmessage

Themessagefromprocess6072:secondmessage

Themessagefromprocess6072:quit

linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)

上一頁 1 2 3 下一頁

評論


相關推薦

技術專區(qū)

關閉