在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 進(jìn)程間通信之:消息隊(duì)列

            進(jìn)程間通信之:消息隊(duì)列

            作者: 時(shí)間:2013-09-13 來(lái)源:網(wǎng)絡(luò) 收藏

            本文引用地址:http://www.biyoush.com/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;

            /*根據(jù)不同的路徑和關(guān)鍵字產(chǎn)生標(biāo)準(zhǔn)的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)內(nèi)核中移走消息隊(duì)列*/

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

            {

            perror(msgctl);

            exit(1);

            }

            exit(0);

            }

            以下是程序的運(yùn)行結(jié)果。輸入“quit”則兩個(gè)進(jìn)程都將結(jié)束。

            $./msgsnd

            Openqueue327680

            Entersomemessagetothequeue:firstmessage

            Entersomemessagetothequeue:secondmessage

            Entersomemessagetothequeue:quit

            $./msgrcv

            Openqueue327680

            Themessagefromprocess6072:firstmessage

            Themessagefromprocess6072:secondmessage

            Themessagefromprocess6072:quit

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

            上一頁(yè) 1 2 3 下一頁(yè)

            評(píng)論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉