Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when a process reads an IPC message via msgrcv? [closed]

Tags:

c++

c

linux

What happens when a process reads an IPC message with msgrcv?

Why I can't read a message with the same mtype more than once?

Code for the structure being used:

struct msgbuff{
    long mtype;
    char mtext[150];   
};
like image 767
DNA Avatar asked Nov 04 '22 06:11

DNA


1 Answers

A message can only be read once. This is how the msgrcv manpage describes its function:

The msgrcv() system call removes a message from the queue specified by msqid and places it in the buffer pointed to by msgp.

There is no way to peek at the queue. If you need that you could pop an item from the queue with msgrcv() and then add it again using msgsnd(). There is a risk that will fail (queue full, out of memory, etc.) so it is not foolproof.

like image 129
Wichert Akkerman Avatar answered Nov 10 '22 17:11

Wichert Akkerman