[Cpp]
// Ipcs-q-I 0
// Semaphore Arrays
// Shared Memory Segments
// Messages Queues
# Include <sys/ipc. h>
# Include <string. h>
# Include <unistd. h>
# Include <sys/types. h>
# Include <sys/msg. h>
# Include <stdio. h>
# Include <stdlib. h>
# Include <errno. h>
Struct msgbuf {
Long mtype;
Char mtext [100];
};
Int main ()
{
Key_t key;
Int msgid;
Struct msgbuf msg1, msg2, msg3, msg4;
Key = ftok ("/home/web", 'A ');
If (msgid = msgget (key, IPC_CREAT | 0666) <0 ){
Printf ("msg err \ n ");
Printf ("% s \ n", strerror (errno ));
Exit (-1 );
}
Printf ("please input your name: \ n ");
Msg1.mtype = 1;
Strcpy (msg1.mtext, "text1 ");
Msg3.mtype = 3;
Strcpy (msg3.mtext, "text3 ");
Msg4.mtype = 4;
Strcpy (msg4.mtext, "text4 ");
// Msgsnd (msgid, & msg1, sizeof (msg1.mtext), 0 );
// Msgsnd (msgid, & msg3, sizeof (msg3.mtext), 0 );
// Msgsnd (msgid, & msg4, sizeof (msg4.mtext), 0 );
Msgrcv (msgid, & msg2, 100,4, 0 );
Printf ("--- % s \ n", msg2.mtext );
Return 0;
}