zoukankan      html  css  js  c++  java
  • 操作系统实验代码

    snd.c

    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/msg.h>
    #include <string.h>
    #include <stdio.h>
    #define key  80
    struct msg {
       long mtype;
        int snd_id;
        char txt[128];
    };
    int len=sizeof(struct msg) - sizeof(long);
    main()
    {
         int qid;
         struct msg m;
         qid=msgget(key,0777|IPC_CREAT);	
         m.mtype=1;	
         m.snd_id=getpid(); 
         strcpy(m.txt,"aaaaa");   
        printf("qid=%d
    ",qid);
        msgsnd(qid,&m,len,0);
        msgrcv(qid,&m,len,getpid(),0);
        printf("pid=%d,%s
    ",m.snd_id,m.txt);
        getchar();	
    }	  
    

    rcv.c

    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/msg.h>
    #include <string.h>
    #include <stdio.h>
    #define key  80
    struct msg {
       long mtype;
        int snd_id;
        char txt[128];
    };
    int len=sizeof(struct msg) - sizeof(long);
    main()
    {
         int qid;
         int pid=getpid();
         struct msg m;
         qid=msgget(key,0777);	
        printf("qid=%d",qid);
        msgrcv(qid,&m,len,1,0);
        printf("pid=%d,%s
    ",m.snd_id,m.txt);
         m.mtype=m.snd_id;	
         m.snd_id=pid; 
         strcpy(m.txt,"bbbbb");
        msgsnd(qid,&m,len,0);
        getchar();
    }	  
    
  • 相关阅读:
    java:第三章
    java:第一章
    java:第二章
    复制a.jpg到b.jpg
    安卓事件大全
    安卓事件
    read输入流与writer输出流的对比
    第五章:循环结构
    第三章:选择结构(一)
    第二章:变量,数据类型和运算符
  • 原文地址:https://www.cnblogs.com/zhangbolin/p/13998136.html
Copyright © 2011-2022 走看看