/* * Um processo envia e 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; #define MSG_SIZE sizeof(Msgbuf) Msgbuf inbuf, outbuf; int main() { int queue_id; if ((queue_id = msgget(IPC_PRIVATE, IPC_CREAT | 0700)) == -1) perror("msgget"); outbuf.mtype = MY_MSGTYPE; outbuf.mtext[0] = '#'; if (msgsnd(queue_id, &outbuf, MSG_SIZE, 0) == -1) perror("msgsnd"); printf("Mensagem enviada = %c\n", outbuf.mtext[0]); if (msgrcv(queue_id, &inbuf, MSG_SIZE, MY_MSGTYPE, MSG_NOERROR) == -1) perror("msgrcv"); printf("Mensagem recebida = %c\n", inbuf.mtext[0]); return 0; }