#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <signal.h>

#include <stdio.h>
#include <unistd.h>

struct message {
	long mtype;
	char mtext[80];
};


int main(void)
{
	int msg_q;
	struct message msg;
	struct msqid_ds msg_s;
	msg_q = msgget(IPC_PRIVATE,IPC_R | IPC_W);
	if(msg_q < 0) {
		perror("error creating message queue");
		return 0;
	}
	msg.mtype = 1;
	strncpy(msg.mtext,"Hello.\n",80);
	msgsnd(msg_q,&msg,sizeof(struct message),0);
	msgrcv(msg_q,&msg,sizeof(struct message),0,0);
	printf("%s",msg.mtext);
	msgctl(msg_q,IPC_RMID,&msg_s);
}

