/* * Um processo recebe uma mensagem. */ #include #include #include #include #include #define MY_MSGTYPE 1 typedef struct msgbuf { long mtype; /* type of message */ char mtext[1]; /* message text .. why is this not a ptr? */ } Msgbuf; Msgbuf inbuf; int main() { int r; key_t key; int queue_id; if ((key = ftok("myqueue", 1)) == -1) perror("Erro em ftok"); if ((queue_id = msgget(key, 0700)) == -1) perror("Erro em msgget"); r = msgrcv(queue_id, &inbuf, sizeof(Msgbuf), MY_MSGTYPE, MSG_NOERROR); if (r == -1) perror("Erro em msgrcv"); else printf("Mensagem recebida: %c\n", inbuf.mtext[0]); return 0; }