操作系统 进程间通信实验题之消息队列

/*实验题目
1. 编写一对程序:(1)发送端客户程序ctest_name;(2)接收方服务器程序stest_name;要求:
# ctest msg1 3
# ctest msg2 4
# ctest msg3 1
# ctest msg4 9
(3,4,1,9只是优先级模板,每个同学用自己学号倒数第1/2/3/4位的值填充优先级,若有重复的则顺取倒数前一位)
# stest
server pid is 2345
priority 1 msg3
priority 3 msg1
priority 4 msg2
priority 9 msg4
*/
/*ctest_name.c与stest_name.c均有的头文件和结构体*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/types.h>
#include <unistd.h>
#define MAX_MSGSIZE 256
#define MSG_KEY (key_t)1234
#define SERVER_MSG_TYPE (long)10
#define CLIENT_MSG_TYPE (long)20

struct client
{
    char text[MAX_MSGSIZE]; //消息的内容
    int priorityNum;        //消息的优先级
};
struct Message
{
    long type;              //消息的类型(long型)
    struct client info;     //客户端结构体消息
};
/*ctest_name.c*/
/*stest_name.c*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值