Home > OS >  You can't get a message the message queue, has been blocked.
You can't get a message the message queue, has been blocked.

Time:09-20

/* * * * * send. C * * * * */
 # include 
# include
# include
# include
# include

Struct msgbuf
{
Int msg_type;
Char msg_text [1024].
};

Void main ()
{
Key_t key;
Int msgid;
The int type.
Char buf [1024].
Struct msgbuf MSGST;

Msgid=msgget (1024, IPC_CREAT);

While (1)
{
Printf (" do input type of message: (0 to exit!) \n");
The scanf (" % d ", & amp; Type);
If (type==0)
break;
Printf (" both please input the content of the message: \ n ");
The scanf (" % s ", buf);

MSGST. Msg_type=type;
Strcpy (MSGST msg_text, buf);
Printf (" type: % d \ ncontent: % s \ n ", MSGST. Msg_type, MSGST. Msg_text);

MSGSND (msgid, & amp; MSGST, sizeof (struct msgbuf), 0);

}

MSGCTL (msgid, IPC_RMID, 0);

}

/* * * * * * the receive. C * * * * * * * */
 # include 
# include
# include
# include
# include

Struct msgbuf
{
Int msg_type;
Char msg_text [1024].
};

Void main ()
{

Key_t key;
Pid_t pid;
Long int type.
Char buf [1024].
Int msgid;
Struct msgbuf MSGST;

Msgid=msgget (1024, IPC_EXCL);

While (1)
{

Printf (" both Please enter the number of message type you want to receive: (0 to exit) \ n ");
The scanf (" % ld ", type);

If (type==0)
break;

MSGRCV (msgid, & amp; MSGST, sizeof (struct msgbuf), type, 0);

Content: printf (" % s \ n ", MSGST. Msg_text);
}

MSGCTL (msgid, IPC_RMID, 0);

}


Can send the send process, using the ipcs view also has the message queue, but don't get the message the receive process, has been in the blocking state, a great god show
  • Related