0
votes

I have a hard requirement to forcefully destroy a posix message queue with a given name.

I have found out by trial and error that this command wont do

 mq_unlink(BROKER_NAME);

The problem with above is that even after unlink, the queue exists as long as other threads/processes reference it.

Is there a way to forcefully destroy the queue, no questions asked?

I will also have file descriptor to the queue.

1

1 Answers

1
votes

You can not force the queue to be destroyed as long as it's still in use

Per POSIX mq_unlink() (bolding mine):

If one or more processes have the message queue open when mq_unlink() is called, destruction of the message queue shall be postponed until all references to the message queue have been closed.

You have to have all processes using the queue also close their connection(s).