/* * Um processo envia 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 outbuf; 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, IPC_CREAT | 0700)) == -1) perror("Erro em msgget"); outbuf.mtype = MY_MSGTYPE; outbuf.mtext[0] = '*'; r = msgsnd(queue_id, &outbuf, sizeof(Msgbuf), 0); if (r == -1) perror("Erro em msgsnd"); else printf("Mensagem enviada: %c\n", outbuf.mtext[0]); return 0; }