I want to delete all the messages from the POSIX message queue. I searched on the internet but I didn't find any way to do it instead I found the way to delete the message queue itself but that's not my case I actually want to clear all the pending messages from the message queue.
I was reading the man page in which I found mq_setattr API which is used to control the parameter for the message queue. I was just wondering if I set the value of mq_curmsgs to 0 by using mq_setattr, would it clear the pending messages from the queue?
Any help in this regard will be appreciated
One way to clear a message queue is to mq_receive all messages but not process them.
man mq_setattr:
The only attribute that can be modified is the setting of the O_NONBLOCK flag in mq_flags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With