LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2007, 03:39 PM   #1
stupendus
LQ Newbie
 
Registered: Jul 2005
Posts: 15

Rep: Reputation: 0
msgget, msgsnd and msgrcv


Hi all,
I'm debugging some code that involves use of msgget, msgsnd and msgrcv.
I (hope I) have understood the idea of queues that lies behind, so I have rather a specific question.

How many messages can you send on a queue before hanging forever while trying to send another one?

If I send a message, and then another one, my program stops here:

if (msgsnd( msgqueue_id, (struct msg *)(&themessage), len, 0)) ==-1) {
cout << "Some troubles in sending message..." << endl;
}

What happens is that msgsnd will never return, unless I force a msgsnd, by changing msgflg from 0 to IPC_NOWAIT. In this way msgsnd returns -1 and sets errno to EAGAIN.

So I modify my code in order to loop in this way:

while ( (msgsnd( msgqueue_id, (struct msg *)(&themessage), len, IPC_NOWAIT)) ==-1) {
if ( errno == EAGAIN ) {
cout << "errno is : " << errno << endl;
}
struct *msg msgbuf;
msgrcv(msgqueue_id, (struct msgbuf *)(&msgbuf), len , to, IPC_NOWAIT);
if ( msgbuf != NULL ) {
cout << "There are some messages in the queue... \n Flushing them..." << endl;
cout << "to : " << msgbuf->to << endl;
...
}
}
I always find just one message. This happens twice in the code. Then, after each 'sndmsg' there is its own msgrcv...

Any idea of the queue capability?

Many thanks in advance!

Ciao,
Marco
 
Old 08-06-2007, 05:45 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Have you looked at Beej's Guide to Unix IPC? How about Dave Marshall's Programming in C Tutorial? Both of these should have enough information to get you through your problem.
--- rod.
 
Old 08-06-2007, 05:56 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Oh, yeah. I believe the queue is limited by the total size of all messages. On Linuxes that I have used, the maximum queue size was 16K bytes. I don't know it there is a limit on the total number of messages. My system sends small messages, 4 & 6 bytes, and never ran into any limit before the byte count was exceded. You can observe the state of all queues with the 'ipcs' tool.
--- rod.
 
Old 08-07-2007, 04:18 AM   #4
stupendus
LQ Newbie
 
Registered: Jul 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Hi,
first of all, many thanks for the very useful guides you pointed me too!

Ok, I discovered that the information I was looking for is here:

#define MSGMAX 8192 /* <= INT_MAX */ /* max size of message (bytes) */
#define MSGMNB 16384 /* <= INT_MAX */ /* default max size of a message queue */

/usr/src/kernels/2.6.9-55.0.2.EL-i686/include/linux/msg.h

Moreover, I can use

msgctl(msqid, IPC_STAT, &buf)

to have:

printf("%s%d%s","msg_qbytes : ",buf.msg_qbytes,"\n");

Thanks again!

Ciao,
Marco
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IPC V message queue --msgsnd() call jasdeep.js Linux - Kernel 1 01-02-2007 06:59 PM
msgrcv timeout yhus Programming 1 11-29-2006 07:22 AM
msgsnd (sys_msgsnd) symbol unresolved yhus Programming 0 09-06-2005 01:49 AM
msgrcv problem chiahsin Linux - Software 0 12-02-2004 03:56 AM
msgget related problem on Linux bhooshan Linux - General 0 05-26-2003 01:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration