乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      消息隊(duì)列實(shí)現(xiàn)進(jìn)程間通信

       Ethan的博客 2011-11-19
      /*客戶端*/
      #include<sys/types.h>
      #include<sys/msg.h>
      #include<sys/ipc.h>
      #include <stdio.h>

      #define MSGKEY 75
      struct msgform{
       long mtype;
       char mtext[1000];
      }msg;
      void client(){
       int msgid;
       key_t msgkey;
       struct msgform msgdata,*p;
       p=&msgdata;

       msgkey=ftok("mrecv",'a');
       /*打開標(biāo)識(shí)號(hào)為MSGKEY的消息隊(duì)列*/
        msgid=msgget(msgkey,IPC_CREAT|0666);
        int i;
        for(i=10;i>=1;i--){
         printf("輸入消息:");
          gets(p->mtext);
          p->mtype=i;
        printf("(client)sentt\n");
        /* 發(fā)送消息msg*/
         msgsnd(msgid,p,sizeof(p->mtext),0);
        }
        /*退出系統(tǒng)*/
        exit(1);
        }


       
         int main(){
            client();
            return 0;
         }

      **************************華麗的分割線*********************
      /*服務(wù)端*/

      #include <sys/types.h>
      #include<sys/msg.h>
      #include<sys/ipc.h>
      #define MSGKEY 75
      struct msgform{
       long mtype;
       char mtext[1000];
      }msg;
      void server(){
       key_t msgkey;
       int msgid;
       int reval;
       /*創(chuàng)建標(biāo)識(shí)號(hào)為MSGKEY的消息隊(duì)列*/
        struct msgform msgdata,*p;
        p=&msgdata;
        msgkey=ftok("mrecv",'a');
        msgid=msgget(msgkey,IPC_CREAT|0666);

        do{
        /*接收消息*/
         reval=msgrcv(msgid,p,sizeof(p->mtext),0,0);
         if(reval==-1){
         printf("read msg error\n");
        
         }else printf("read from msg queue%d bytes\n",reval);
         /*打印“接收到消息”提示信息*/
          printf("接收到的消息:%ld\n%s\n",p->mtype,p->mtext);
        }while(p->mtype!=1);
        /*刪除消息隊(duì)列,歸還資源*/
        msgctl(msgid,IPC_RMID,p);
        /*退出*/
        exit(1);
       
        }


        int main(){
        server();
        return 0;
        }



      結(jié)果:
       


       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多