U
U
UncleAndy2012-06-27 14:10:20
Perl
UncleAndy, 2012-06-27 14:10:20

IPC::SysV - how to determine the fullness of the message queue in shared memory?

I have a task in which the transfer of information between processes is organized through queues in shared memory using the msgsnd / msgrcv commands. Everything works fine until a situation arises when the queue overflows and msgsnd does not work.
I need to somehow detect the message queue overflow situation. The msgsnd command returns false in non-blocking mode. On this basis, I need to somehow determine that the problem is in the overflow of the queue, and not some other (for example, that some other process did not close this queue). It seems that this can be done using the msgctl function and the IPC_STAT command. But I did not find a single example of its use on the Internet.
Maybe some other methods will work for my task? I would be grateful for links or examples.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ToSHiC, 2012-06-27
@ToSHiC

Check the $! variable, the pearl stuffs errno into it. And then look in man 2 msgsnd:

Значения errno, устанавливаемые при выполнении функции msgsnd:
EAGAIN
Сообщение не может быть помещено в очередь, потому что размер очереди превысит лимит, равный msg_qbytes , а в параметре mgsflg установлен флаг IPC_NOWAIT.
EACCES
Вызывающий процесс не имеет прав записи в очередь.
EFAULT
Память с адресом, указанным msgp, недоступна.
EIDRM
Очередь сообщений была удалена из системы.
EINTR
Процесс ждал свободного места в очереди и получил сигнал, который он должен обработать.
EINVAL
Задано неправильное значение msqid, неположительное значение mtype или неправильное значение msgsz (меньшее, чем 0, или большее, чем системный лимит, заданный MSGMAX).
ENOMEM
В системе недостаточно памяти для копирования содержимого буфера msgbuf.

E
edem, 2012-06-27
@edem

perl -d yourscript.pl
has never failed. go through all the problematic lines in the code step by step, and look at the dumps of the variables you need, it should help.

U
UncleAndy, 2012-06-27
@UncleAndy

The problem is not to identify the problem when debugging, but to handle the runtime situation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question