There is no information after Message Queuing is sent under Linux

Source: Internet
Author: User
Tags message queue

When using Message Queuing, call the

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/msg.h>

struct MYMSG

{

Long MyType;

Char even[32];

};

#define VALUE (key_t) 0x1fff

int main ()

{

struct mymsg msg;

int msgid,res;

MsgId = Msgget (VALUE, 0666 | Ipc_creat);

Res =msgsnd (MsgId, &msg, sizeof (msg), 0);

}

After executing the above procedure, there is no error.

Use Ipcs-q to view the message queue, which contains 0.

Looking for a long time, the original is the use of msgsnd () function, the structure of the MyType is not assigned. Causes the message queue not to enter.

Add this sentence to the Msgget () function:

Msg.mytype = 1;

The compile run can see messages in the message queue.

There is also an issue to be aware of using the msgsnd () function, which is if you memset (&msg, 0, sizeof (msg)); mytype=0

This is not the case, mytype=0 can only be MSGRCV () when set, meaning to receive all messages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.