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

/*实验题目
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*/

猜你喜欢

转载自blog.csdn.net/JxufeCarol/article/details/90273887
今日推荐