Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:37:29+00:00 2026-05-24T06:37:29+00:00

Why is there a error Cannot Allocate Memory while creating message queue in POSIX?

  • 0

Why is there a error “Cannot Allocate Memory” while creating message queue in POSIX?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:37:30+00:00Added an answer on May 24, 2026 at 6:37 am

    Adrian’s answer is correct, but since this is a frustratingly common error to run into on Linux when first attempting to use POSIX message queues for anything non-trivial, I thought I’d add some helpful particulars.

    First, to understand the RLIMIT_MSGQUEUE resource limit, see the formula at man setrlimit:

    RLIMIT_MSGQUEUE (Since Linux 2.6.8)
    Specifies the limit on the number of bytes that can be allocated for POSIX message queues for the real user ID of the calling process. This limit is enforced for mq_open(3). Each message queue that the user creates counts (until it is removed) against this limit according to the formula:

    bytes = attr.mq_maxmsg * sizeof(struct msg_msg *) +
            attr.mq_maxmsg * attr.mq_msgsize
    

    where attr is the mq_attr structure specified as the fourth argument to mq_open(3).
    The first addend in the formula, which includes sizeof(struct msg_msg *) (4 bytes on Linux/i386), ensures that the user cannot create an unlimited number of zero-length messages (such messages nevertheless each consume some system memory for bookkeeping overhead).

    Given the default MQ settings (mq_maxmsg = 10, mq_msgsize = 8192) on Linux, the above formula works out to only about 10 message queues for the default limit of 819200 bytes. Hence why you will run into this problem as soon as you e.g. forget to close and unlink a couple of queues once done with them.

    To raise the RLIMIT_MSGQUEUE resource limit to the maximum allowed for the user, you can use something like the following in your application’s startup code:

    #ifdef __linux__
        // Attempt to raise the resource limits for POSIX message queues to
        // the current hard limit enforced for the current real user ID:
        struct rlimit rlim = {RLIM_INFINITY, RLIM_INFINITY};
        const int rc = getrlimit(RLIMIT_MSGQUEUE, &rlim);
        if (rc == 0 && rlim.rlim_cur != rlim.rlim_max) {
          rlim.rlim_cur = rlim.rlim_max;
          setrlimit(RLIMIT_MSGQUEUE, &rlim);
        }
    #endif
    

    If you also ensure that you set the mq_maxmsg and mq_msgsize attributes to lower values when opening a queue (see man mq_open), you may be able to get away with a couple of hundred queues even within the constraints of the default RLIMIT_MSGQUEUE hard limit. Depending on your particular use case, of course.

    Adjusting the RLIMIT_MSGQUEUE hard limit is not difficult if you have root access to the system. Once you’ve figured out what the limit ought to be, adjust the system-wide settings in /etc/security/limits.conf. For example, to set a hard and soft limit of 4 megabytes for the www-data user group, and no limitation for the superuser, you’d add the following lines to the file:

    @www-data   -   msgqueue    4194304
    root        -   msgqueue    unlimited
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you ever seen any of there error messages? -- SQL Server 2000 Could
Why is there no error issued by strict : use strict; $a = $a
When debugging in Visual Studio 2008 I get the error There is no source
When we try to create a view within a funcion we get ERROR: there
I got this project, where there this error keeps occurring and its not on
With MVC stuff when there is an error on property level, we can add
Recently I came across this error in my WCF trace: There was an error
The following line of code generates the compile time error (PE19) There is no
I have configured a SMTP appender to send an email whenever there's an error.
Say you have an enum that represents an error code. There will be several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.