Hello everybody
I am writing a mini program in Linux
I have a message queue which has a default maximum capacity of
bytes that can be written in it.
I am trying to modify this capacity. I googled for a solution and tried
to change the value of (msg_qbytes) by writing these instructions :

key_t key;
key =111;
int msgflg = IPC_CREAT | 0666;
int msqid;
struct msqid_ds msqid_ds,*BUF;
BUF = &msqid_ds;
msqid = msgget(key,msgflg);
int result;
result= msgctl(msqid,IPC_SET,BUF);
BUF->msg_qbytes = 50;

After that I wrote some instruction to test the ability of
queue of recieving messages ,but I found that the message queue still recieving
amount of messages more than 50 bytes which shows that the capacity af the
message queue haven't changed.
Would you plz guide me to a solution for this problem?

Recommended Answers

All 2 Replies

You did it backwards. msgctl copies data from the buf to the kernel space. So, you need to modify BUF with the desired values, and then call msgctl.

Keep in mind that BUF as it is contains garbage. Before any other operations fill it up with the correct values via IPC_STAT.

commented: well and fast answer +1

Thanks alot Mr.nezachem
Your solution worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.