#include #include #include #include #include #include typedef struct mymesg { long int mtype; char mtext[512]; }mymesg; int main(int argc, char *argv[]) { int id = 0; mymesg JGX_msg; key_t key = ftok("my_message", 52); id = msgget(key, IPC_CREAT | 0666); //打开或者创建队列 if (-1 == id) { perror("create msg error"); exit(EXIT_FAILURE); } while(1) { if (-1 == msgrcv(id, (void *)&JGX_msg, sizeof(JGX_msg.mtext), 1,0)) { perror("Recive msg error "); exit(EXIT_FAILURE); } printf("Data:%s", JGX_msg.mtext); if(strncmp(JGX_msg.mtext,"exit",4) ==0) { break; } } return 0; }