Find the answer to your Linux question:
Results 1 to 3 of 3
Actually I dint understand allocation and freeing of memory in message queue. The sender with message id sends message and receiver receives and uses msgctl()-->to free the memory. Now the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    8

    Question Interview question message queue


    Actually I dint understand allocation and freeing of memory in message queue.
    The sender with message id sends message and receiver receives
    and uses msgctl()-->to free the memory.

    Now the quesiotn whct is freeing here ?Is it dynamic?Then it shud have malloc/calloc when allocating?But I dont see any thing here.

    Where from the memory is allocated and where it is freed?

    Please some one help me thanks in advance

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,528
    Huh? The commands available for msgctl() are IPC_STAT, IPC_SET, IPC_RMID, IPC_INFO, MSG_INFO, and MSG_STAT. The only one that really manipulates kernel memory structurs is IPC_SET. You can change the maximum number of bytes allowed in a queue, but a couple of caveates here. One is that you need to have the appropriate privileges. Two is that if you increase the msg_qbytes field in the msqid_ds structure, it will only take effect when you create a new queue. It doesn't affect current queues as far as I know.

    So, you have to manage your own memory as far as local buffers are concerned. The queue code in the kernel handles kernel allocation needs. When you send a message, it is copied by the kernel code into the kernel message structures. When you receive a message, you provide a pointer to a message structure of your own. The kernel code copies the kernel message data received into that buffer.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,528
    You may also want to review the mq_overview man page for more informatioon: man mq_overview
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •