1

I am stuck with quite a strange error in message queue code which used to work completely fine before. The error I am getting is :

 terminate called after throwing an instance of 'std::runtime_error'
      what():  Unable to create named message queue

The code which is throwing the error is:

void VMGR::initialize_mq()
{
    int errsv;   
    queue_attr.mq_flags   = 0;
    queue_attr.mq_maxmsg  = 10;
    queue_attr.mq_msgsize = api::msg_sz;
    queue_attr.mq_curmsgs = 0;

    mq_unlink (api::nm_mqueue);
    mq_close(queue);



    queue = mq_open( api::nm_mqueue, O_RDWR | O_CREAT | O_EXCL|O_NONBLOCK, IO_FILE_PERMISSIONS, &queue_attr );


    if (queue == (mqd_t)-1)
    {
        errsv = errno;
        throw std::runtime_error(
                std::string( "Unable to create named message queue" )
        );
    }
    std::cout<< "initialize_mq works"<< std::endl;
    return;
}

I have checked thoroughly the /dev/mqueue that I am not using the same file descriptor which already exists. Wasted a lot of time on resolving this error. Need help and guidance. Edit After executing ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 1030932
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1030932
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

The number of message queue identifiers presently I have in the system:

Data7aa      vmgr_proc135978  vmgr_proc40571  vmgr_proc55053
Data7bb      vmgr_proc136146  vmgr_proc42152  vmgr_proc56557
Data7cc      vmgr_proc136536  vmgr_proc43732  vmgr_proc9190
Data7dd      vmgr_proc16914   vmgr_proc45247  vmgr_proc93026
Data7ee      vmgr_proc17107   vmgr_proc46576  vmgr_proc9362
Data7gg      vmgr_proc21970   vmgr_proc47958  vmgr_proc93706
Data7hh      vmgr_proc29728   vmgr_proc49422  vmgr_proc93925
hello_moto   vmgr_proc31111   vmgr_proc49700  vmgr_proc94596
vmgr_proc123434  vmgr_proc32504   vmgr_proc51452  vmgr_proc9528
vmgr_proc132441  vmgr_proc35308   vmgr_proc51869  vmgr_send
vmgr_proc132550  vmgr_proc39121   vmgr_proc53478
  • 1
    what does errno contain? – pm100 Jul 30 '22 at 16:32
  • 1
    Do you know about `errno`, and know how to use it? – Sam Varshavchik Jul 30 '22 at 16:35
  • @pm100 Thank you for your response. errno contains 28 – Manu Chaudhary Jul 30 '22 at 16:36
  • @SamVarshavchik errno contains 28 – Manu Chaudhary Jul 30 '22 at 16:37
  • And what does that mean? There is a way to show what each particular value of errno represents. What does it represent on your platform? Different platforms use different values of errno to mean different things, so a numerical value is completely meaningless. What does this error code represent on your system? – Sam Varshavchik Jul 30 '22 at 16:40
  • @SamVarshavchik I am using a linux(ubuntu) system. Not sure how to check it. On google search, it says no space left on the device, but there is a plenty of space in thedevice. – Manu Chaudhary Jul 30 '22 at 16:44
  • ENOSPC Insufficient space for the creation of a new message queue. This probably occurred because the queues_max limit was encountered; see mq_overview(7). – pm100 Jul 30 '22 at 16:45
  • What are you using Google to look up what `errno` is? Do you know what `perror()` is, and how to use it? You can't realistically expect to learn core programming skills by running Google searches, or asking one question at a time on Stackoverflow; it makes much more sense to get a good textbook that fully explains these fundamental concepts. Neither Google, nor Stackoverflow, work very well as textbook replacements. – Sam Varshavchik Jul 30 '22 at 16:48
  • @pm100 In my system, there are only 15 message queue identifiers present. It is out lab system with quite a good configuration. Is there a way to resolve it? This system is a multiuser system because of which I cannot Restart the system. – Manu Chaudhary Jul 30 '22 at 16:48
  • Run `errno 28` in a Terminal. – 273K Jul 30 '22 at 16:50
  • @273K I cannot install errno in the system because I donot have administrator rights. Any other way to check it? – Manu Chaudhary Jul 30 '22 at 16:55
  • @273K In my ubuntu laptop, it gives ENOSPC 28 No space left on the device. – Manu Chaudhary Jul 30 '22 at 17:00
  • Use `ulimit -a` and attempt to determine which limit you are exceeding. Could be total message queue bytes, or number of open files. – stark Jul 30 '22 at 17:05
  • I suggest that you read the manual completely: *`mq_unlink()` removes the specified message queue name. The message queue name is removed immediately. **The queue itself is destroyed once any other processes that have the queue open close their descriptors referring to the queue.*** Thus, open descriptor count does not decrease immediately and the limit can be kept exceeded after `mq_unlink()`. – 273K Jul 30 '22 at 17:11
  • Thank you @stark for your response. I have edited the question to include the result of ulimit -a and /dev/mqueue. Please review. – Manu Chaudhary Jul 30 '22 at 17:11
  • What prompted you to post images instead of a formatted text? Downvoted for images. – 273K Jul 30 '22 at 17:13
  • https://stackoverflow.com/q/18786466/1216776 – stark Jul 30 '22 at 17:14
  • @273 Removing mq_unlink from the initial lines resolved the problem. Thank you all for great help. – Manu Chaudhary Jul 30 '22 at 17:36
  • Just want to finally update the problem. When we deleted all unnecessary message queues identifiers from /dev/mqueue , the error got resolved automatically without changing the code. – Manu Chaudhary Jul 30 '22 at 18:17
  • Just my final update regarding this question. The real reason of the error 28 was that a large number of processes were running in background in our systems(about 400 processes). Once we killed all these processes, this problem was completely solved. Thank you for everyone help. – Manu Chaudhary Aug 06 '22 at 07:44

0 Answers0