免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
消息隊(duì)列實(shí)現(xiàn)進(jìn)程間通信
/*客戶端*/
#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é)果:
 


 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Linux進(jìn)程間通信
Linux 進(jìn)程間通信方式(轉(zhuǎn))
linux消息隊(duì)列操作
進(jìn)程間通信——消息隊(duì)列
Linux環(huán)境進(jìn)程間通信(三): 消息隊(duì)列
消息隊(duì)列的使用
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服