Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-03-2009, 09:51 PM   #1
LQ Newbie
Registered: Feb 2009
Posts: 1

Rep: Reputation: 0
ENOMEM on mq_open() call

I need help. I am relatively new to Linux. I have a program that uses message queue using the mq_open() call to create one. When the program is waiting for a message in the queue (blocking) and I abort the program using control-C, I am getting the ENOMEM error (cannot allocate memory) from mq_open() call after only repeating the scenario 3 to 4 times. I am aware that the message queue is persistent in the kernel and this causes memory leak. The only way to make it to work again is reboot the Linux machine. Is there a way that my program can check for any un-removed message queues and clean it up? But is the best solution for this type of problem? Thanks.
Old 02-13-2011, 10:40 PM   #2
LQ Newbie
Registered: Feb 2011
Location: Sri Lanka
Posts: 9

Rep: Reputation: 0
Hello All,

Someone please respond, I'm having the trouble too. I've caught the ctrl+c signal and I'm closing all the message queues at the destructor. But still the mq_open: cannot allocate memory problem exists. Have somebody figured this out? This is some old thread, has roxasmn found a remedy?
Old 02-13-2011, 11:35 PM   #3
Senior Member
Registered: Dec 2008
Posts: 4,724
Blog Entries: 29

Rep: Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931
Have you checked all the memory leaks through valgrind? or hitting Google by the keyword ENOMEM might give something to dwell upon.

and the mq_close call returns 0 as expected?

Last edited by TheIndependentAquarius; 02-13-2011 at 11:36 PM.
Old 02-13-2011, 11:48 PM   #4
Registered: Jan 2011
Distribution: RedHat,Debian-Ubuntu,Fedora
Posts: 73

Rep: Reputation: 8
can you try mq_unlink .more details on man page.
Old 02-14-2011, 12:27 AM   #5
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You can use "mq_unlink()" to try to clean things up programmatically.

You can also use "ipcs" and "ipcrm" (much easier than rebooting the PC ) from the command line.
Old 02-15-2011, 12:48 AM   #6
LQ Newbie
Registered: Feb 2011
Location: Sri Lanka
Posts: 9

Rep: Reputation: 0
Hello all,

Thank you all for your very quick replies.
I have indeed used mq_unlink command to terminate the message queues.
Thanx for pointing out "ipcs" command. Now there's a major problem. In my program I create 2 threads which create message queues for communication. Still, when the program is running, "IPCS" command output doesn't show anything. It says no shared memory/MQ/Semaphore. I'm confused, does that mean my problem is not related to message queues? And why it doesn't show any message queues?
Bdw, I'm running the system on a arm based core
Old 08-10-2011, 11:16 AM   #7
LQ Newbie
Registered: Aug 2011
Distribution: xubuntu 11.04
Posts: 1

Rep: Reputation: Disabled
ipcs Shows system V message queues not POSIX message queues

If one process calls mq_unlink on a queue where another still has the queue open
then the resources allocated to the queue are not reclaimed until it is closed
by the second process. This can give ENOMEM errors when trying to create new queues.

You can use /proc to spot open queue descriptors for a process eg:

ls -l /proc/<pid>/fd

lr-x------ 1 steve steve 64 2011-08-10 16:08 4 -> /myq1
l-wx------ 1 steve steve 64 2011-08-10 16:09 5 -> /myq2 (deleted)


message, queue

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
mq_open error mageshvan Programming 1 10-08-2007 12:05 PM
mq_open error ('invalid arg') on RHEL4 lambert_anne Programming 1 03-14-2007 08:12 AM
mq_open fails on Suse 9.2 / 9.3 supaflav Programming 1 11-04-2005 01:12 PM
ENOMEM in do_get_write_access, retrying da_kidd_er Linux - Enterprise 1 11-18-2004 09:07 PM > Forums > Linux Forums > Linux - Software

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

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