#include    <stdio.h>
#include    <sys/types.h>
#include    <sys/ipc.h>
#include    <sys/msg.h>

void main()
{
int     qid;
struct  {
    long    mtype;
    char    mtext[512];
}buf;

    if((qid=msgget(123,0666|IPC_CREAT))==-1){
        perror("msgget");
        exit(-1);
    }

    while(1){
        fgets(buf.mtext,sizeof(buf.mtext)-1,stdin);
        buf.mtype=1L;
        if(msgsnd(qid,&buf,sizeof(buf.mtext)-sizeof(buf.mtype),0)==-1){
            perror("msgsnd");
            break;
        }
        if(strcmp(buf.mtext,"end")==0){
            break;
        }
    }
}
