0

I create 4 child process and communicate between by a message queue for a couple. I successes to do that bur after a couple of execution it gives error "Cannot allocate memory". I guess it is caused by not deleting the existing queues properly. Do i need to close or unlink in each child process execution before end of the program or it is enough to close them in the parent process. OR is there any way to close - unlink these on the command line (shell) with some commands. Any suggestions! I need to restart the system as a solution but it takes time of course.

Thanks for help!!

4
  • Post your code (or part of it) - we are not psychic. Commented Mar 12, 2011 at 13:22
  • it is HW assignment do I do not wan to get plagiarism with any one Commented Mar 12, 2011 at 13:30
  • 2
    @user: If you provide your teacher with a link to this question (which would be the honest thing to do anyway), nobody can get away with plagiarizing your code. Commented Mar 12, 2011 at 13:45
  • 1
    +100 for larsmans; being afraid of another student ripping off code posted when trying to get SO to help with homework is beautifully absurd. Commented Mar 12, 2011 at 17:32

2 Answers 2

1

You can unlink POSIX messages queues either using the C API or using the shell if you mount the MQ virtual filesystem as per the instructions in man mq_overview (which will give you a "directory" on "disk" (not really, of course), where you can then use commands like ls and rm.

The man pages also discuss the relevant limits that are blocking you from creating new queues when others have not been properly discarded.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, you need to call mq_close() in each child process or the queue won't be removed. The help for mq_unlink() says,

If one or more processes have the message queue open when mq_unlink() is called, destruction of the message queue is postponed until all references to the message queue have been closed. However, the mq_unlink() call need not block until all references have been closed; it may return immediately.

http://pubs.opengroup.org/onlinepubs/007908799/xsh/mq_unlink.html

1 Comment

This is basically the same way normal files work on Unix (they aren't actually removed until the last open descriptor is closed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.