char pathname[] = "./test";
if((key = ftok(pathname,0)) < 0){
printf("Can\'t generate key\n");
if((msqid = msgget(key, 0777 | IPC_CREAT)) < 0){
printf("Can\'t get msqid\n");
for (i = 1; i <= 5; i++){
strcpy(mybuf.mtext, "This is text message from program1");
len = strlen(mybuf.mtext)+1;
if (msgsnd(msqid, (struct msgbuf *) &mybuf, len, 0) < 0){
printf("Can\'t send message to queue\n");
(struct msqid_ds *) NULL);
mybuf.mtype = LAST_MESSAGE;
if (msgsnd(msqid, (struct msgbuf *) &mybuf, len, 0) < 0){
printf("Can\'t send message to queue\n");
(struct msqid_ds *) NULL);
if ( len = msgrcv(msqid, (struct msgbuf *) &mybuf, maxlen, 0, 0) < 0){
printf("Can\'t receive message from queue\n");
if (mybuf.mtype == LAST_MESSAGE){
(struct msqid_ds *) NULL);
printf("message type = %ld, info = %s\n", mybuf.mtype, mybuf.mtext);