SysV message queue number increase

410 views Asked by At

I have a scenario where:

1: there is a reader process and a writer process, these processes are communicating through SysV message queue.

2:Writer process is faster than reader process, that is, writer process writes messages in the queue faster than reader process reads a message and empty the queue, for example if I have 8 messages in the queue (single message queue) and reader process is yet to read one message at that time writer process trying to write (msgsnd) the 9th message in the queue.

3: What will happen will any of my message will get overwritten ?

4: or my last or first message in the queue will get overwritten ?

5: or the entire queue will be overwritten ?

6: or else the 9th message will be lost ?

7: How can I make sure that none of these scenario happens and I will not loose any new incoming message and no existing messages will get overwritten ?

8: How can I handle this situation ?

Regards

1

There are 1 answers

2
Ottavio Campana On

About point 3, the manpage of msgsnd says

When msgsnd() fails, errno will be set to one among the following values:
...
EAGAIN The message can't be sent due to the msg_qbytes limit for the queue
and IPC_NOWAIT was specified in msgflg.

therefore you won't be able to add another message to the queue and you will need to store them somewhere else. If you specified IPC_NOWAIT when you opened the queue, then the message will be lost.