LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-16-2011, 08:41 AM   #1
nerdoctopus
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Rep: Reputation: Disabled
Question Can create only 9 POSIX message queues


Hi all,

I have developed an application on Fedora 14 in C++. I need POSIX message queues for IPC. I need multiple message queues. I create a message queue as below:

MessageQueue = mq_open("/AppMessageQueue", O_RDWR | O_CREAT, 0666, NULL);

From a non-root user, the application can only create 9 message queues. On creation of the 10th message queue, mq_open() generates error ENOMEM. No other application can create a new queue as long as 9 queues are open.

From a root user, the application can create more than 9 queues.

The system variables in /proc are as below:


/proc/sys/fs/mqueue/msg_max - 10
/proc/sys/fs/mqueue/msgsize_max - 8192
/proc/sys/fs/mqueue/queues_max - 256

Why can only 9 queues be created from non-root user?
 
Old 12-16-2011, 10:08 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Run the following command:
Code:
ulimit -q
This should list how many bytes can be allocated towards the creation of message queues. If the number is too small for your needs, you can try to increase it using a similar command, but in this case, specifying the desired size:
Code:
ulimit -q <size>
You also may have better success if you specify the (max) size of the data object you plan to send through your queues. You can do this by specifying the attributes for the queue; for example:
Code:
struct mq_attr attr;
attr.mq_flags   = 0;
attr.mq_maxmsg  = 100;
attr.ms_msgsize = 1000;   /* bytes */
attr.mq_curmsgs = 0;

mqd_t qid = mq_open(name, flags, mode, &attr);
P.S. On my Kubuntu 11.10 system, the result of running 'ulimit -q' is 819200.

Last edited by dwhitney67; 12-16-2011 at 10:11 AM.
 
Old 12-16-2011, 11:13 AM   #3
nerdoctopus
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Smile

Thank you for your reply.

From non-root user:

Code:
$ ulimit -q
819200

$ ulimit -q 1638400
bash: ulimit: POSIX message queues: cannot modify limit: Operation not permitted
Since I need to run the application from non-root user, I need to set the limit in non-root user. However, I get 'Operation not permitted' error.

I will try changing the message size and see if that helps.
 
Old 12-17-2011, 02:39 AM   #4
nerdoctopus
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Smile

I have found the solution.

The process max POSIX queue data size is 819200 bytes. Since I used default attributes in mq_open(), the queue was created with space for 10 messages each message of 8192 bytes. This way, for 10 queues the size limit of 819200 bytes would be reached. So the application was able to create only 9 queues.

I added below lines in /etc/security/limits.conf:

Code:
*       hard    msgqueue        8192000
*       soft    msgqueue        8192000
Before launching the application I do:

Code:
ulimit -q 8192000
This time I do not get "Operation not permitted" error. I launch the application and it can create more than 9 queues!

Thank you for your suggestions. I really appreciate it.
 
Old 12-17-2011, 07:47 AM   #5
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Does your application really need to send messages that are 8192 bytes in size? If you know that your messages will be smaller, then you should specify that size and the max number of messages that can be queued, as I demonstrated earlier.

Otherwise, as you found out, the message queue is created with the default message size (8192 bytes) and a depth of 10 messages.
 
1 members found this post helpful.
Old 12-17-2011, 12:42 PM   #6
nerdoctopus
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Smile

A message can be maximum 2048 bytes in size. So changing the message size and reducing the number of messages in the queue will help in creating more message queues. I will create the messages queues with attributes as you have pointed.

Thank you for your kind support. It was really helpful.
 
  


Reply



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
Posix Message Queues jayadhanesh Programming 1 01-03-2011 11:37 PM
POSIX Queues with message type facility of System V queues ehsan_haq98@yahoo.com Programming 2 12-27-2009 11:45 AM
Posix Message Queues culin Programming 3 04-08-2007 07:01 AM
POSIX message queues(Solaris) to SYS V message queues(Linux) devershetty Programming 1 01-22-2007 10:15 AM
Posix Message queues? gdipierro Programming 20 07-26-2005 04:59 PM

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

All times are GMT -5. The time now is 12:32 PM.

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
Open Source Consulting | Domain Registration