AJ.
AJ.

Reputation: 2569

How can I cleanup the IPC message-queue?

I am using msgget() function in my IPC based application. How can I clean up the queue filled up with old message queues?

Upvotes: 3

Views: 13982

Answers (4)

Arnon Charas
Arnon Charas

Reputation: 108

You can change the message queue attribute for O_NONBLOCK by using mq_setattr. Then empty the queue by reading all of the messages, until the returned value indicates the queue is empty. Now set back the old attributes.

This method is not a run time optimized, but it avoids the need to close and open the message queue.

Upvotes: 2

Andy Ross
Andy Ross

Reputation: 12051

These persistent resource allocation issues (there's a similar one with shared memory) are why the System V APIs are generally considered deprecated. In this case, have you considered using a unix domain socket or FIFO instead of a message queue? Those appear in the filesystem, and can be "cleaned up" when no longer used with tools like rm.

Upvotes: 0

jitter
jitter

Reputation: 54625

To delete a queue, use the following command:

msgctl(msgQID, IPC_RMID, NULL);

SYSTEM CALL: msgctl()

Upvotes: 7

AJ.
AJ.

Reputation: 2569

A work around is to increase MSGMNI System wide maximum number of message queues: policy dependent (on Linux, this limit can be read and modified via /proc/sys/kernel/msgmni).

Upvotes: 1

Related Questions