。。。。。。
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<linux/msg.h>
#define MAXMSG 512
struct my_msg //消息队列结构体
{
long int msg_type;
int i;
char text[MAXMSG];
}msg;
int main(int argc, char const *argv[]){
int msgid = (319,0666|IPC_CREAT);
char buffer[MAXMSG];
printf("msgid = %d\n",msgid);
msg.msg_type=3;
// TO-DO
while(1){
printf("input message :");
scanf("%s", buffer);
strcpy(msg.text, buffer);
msgsnd(msgid, &msg, sizeof(msg.text), IPC_NOWAIT);
}
exit(0);
}
1111111
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<linux/msg.h>
#define MAXMSG 512
struct my_msg //消息队列结构体
{
long int msg_type;
int i;
char text[MAXMSG];
}msg;
int main(int argc, char const *argv[]){
int msgid = msgget(319, 0666|IPC_CREAT);
printf("msgid = %d\n",msgid);
msg.msg_type=3;
while(1){
if(msgrcv(msgid, &msg, sizeof(msg.text), msg.msg_type, IPC_NOWAIT)> 0){
printf("read:msg:\t%s\n", msg.text);
}
}
msgctl(msgid, IPC_RMID, 0);
exit(0);
}
..