System V IPC message queue

System V IPC message queue

Post by John Te » Fri, 09 Nov 2001 11:47:13



Hi,
Would appreciate if anybody can tell me whether there is a "mq_notify"
equivalent in the System V implementation of message queue that tells you
whether there is incoming message in the message queue?
 
 
 

System V IPC message queue

Post by Andrew Giert » Fri, 09 Nov 2001 17:54:50


 John> Hi,
 John> Would appreciate if anybody can tell me whether there is a
 John> "mq_notify" equivalent in the System V implementation of
 John> message queue that tells you whether there is incoming message
 John> in the message queue?

no.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

System V IPC message queue

Post by John Te » Fri, 09 Nov 2001 19:06:46


Quote:>  John> Hi,
>  John> Would appreciate if anybody can tell me whether there is a
>  John> "mq_notify" equivalent in the System V implementation of
>  John> message queue that tells you whether there is incoming message
>  John> in the message queue?

> no.

> --
> Andrew.

Is there a way of alerting a process of an incoming message in the queue?
Maybe with a signal or something? I need to do this because the process has
to do other things and so cannot wait in block mode to receive messages.
Thanx!
 
 
 

System V IPC message queue

Post by Andrew Giert » Fri, 09 Nov 2001 19:58:04


 John> Is there a way of alerting a process of an incoming message in
 John> the queue?

Only by having the sender of the message send a notification via some
other channel.

I've written stuff before (many years ago) that worked that way, and
my advice to anyone thinking of doing likewise is "don't even think
about it".

 John> Maybe with a signal or something?

That's how I did it, but I could never be sure (even after taking
extreme precautions, allowing the signal to be unblocked only at a
specific place in the code) that the program wouldn't deadlock or
lose or delay messages due to unfortunate timing. (I could have done
it properly if the platform I was using had pselect(), but like I said
that was years ago, and even now I don't know any systems offhand that
provide it.)

You _might_ be able to make it work properly if you have all three of:
realtime signals, SA_SIGINFO, and sigqueue().

 John> I need to do this because the process has to do other things
 John> and so cannot wait in block mode to receive messages.

Spawn a subprocess (or a separate thread). Have that read the message
queue, and pass the messages to you via some more convenient mechanism.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

System V IPC message queue

Post by John Te » Sat, 10 Nov 2001 11:52:39


Quote:> Only by having the sender of the message send a notification via some
> other channel.

> I've written stuff before (many years ago) that worked that way, and
> my advice to anyone thinking of doing likewise is "don't even think
> about it".

Other channels? You mean pipes or FIFO? If I'm not wrong, these 2 methods
work similarly to msg queue in the way they receive messages. That means
there is also no way the receiving process can be alerted that there is a
message in the pipe.

Quote:> That's how I did it, but I could never be sure (even after taking
> extreme precautions, allowing the signal to be unblocked only at a
> specific place in the code) that the program wouldn't deadlock or
> lose or delay messages due to unfortunate timing. (I could have done
> it properly if the platform I was using had pselect(), but like I said
> that was years ago, and even now I don't know any systems offhand that
> provide it.)

> You _might_ be able to make it work properly if you have all three of:
> realtime signals, SA_SIGINFO, and sigqueue().

>  John> I need to do this because the process has to do other things
>  John> and so cannot wait in block mode to receive messages.

> Spawn a subprocess (or a separate thread). Have that read the message
> queue, and pass the messages to you via some more convenient mechanism.

Can you give me more details on this one because I'm new to linux
programming. I was thinking maybe you mean this:
1. Fork a child process.
2. loop to check the msg_qnum variable of the msqid_ds structure of the
queue with msgctl ().
3. If there is an increment in msg_qnum, the child will send a realtime
signal to the parent telling it to msgrcv()
the message.

But how is the child gonna communicate with the parent? via pipe or FIFO?
But as i wrote above, according to what limited knowledge i have about pipe
and FIFO, the receiving parent process also cannot be notified of an
incoming message in the pipe. Please enlighten me on this, thanx!

 
 
 

System V IPC message queue

Post by Antti J?rvin » Sat, 10 Nov 2001 19:31:52



> Is there a way of alerting a process of an incoming message in the queue?
> Maybe with a signal or something? I need to do this because the process has
> to do other things and so cannot wait in block mode to receive messages.

Spawn a thread if you have posix threads and let one thread sit in msg queue?

If you're sitting in a loop doing some processing, you can set IPC_NOWAIT
flag for msgrcv to return immediately if there is nothing on the queue and
use that for checking, if you can afford that delay between checkings.

If you're instead sitting in select() or poll() waiting for some event,
then you can't wait for msg queue. You could do select() with rather short
timeout, after timeout check for messages and then go back to select().
In this case it might be easier to replace the msg queue with a pipe
because you can wait for pipe and socket in same select().

But as you were asking for way of notifying, I don't know. Signal that
is but IMHO it is easier to have your reading process to wait for the
queue. This opinion is this because I'm dirt poor in doing signal trapping :)

--

            "concerto for two *s and orchestra"

 
 
 

System V IPC message queue

Post by those who know me have no need of my nam » Sun, 11 Nov 2001 08:18:19



Quote:>> Only by having the sender of the message send a notification via some
>> other channel.
>Other channels? You mean pipes or FIFO? If I'm not wrong, these 2 methods
>work similarly to msg queue in the way they receive messages.

they do not work the same.  you can select (or poll) a pipe but not a
message queue (unless you have pselect, which linux does not).

Quote:>But how is the child gonna communicate with the parent? via pipe or FIFO?

perhaps dying is a sufficient signal, otherwise a signal or writing a pipe.

--
okay, have a sig then

 
 
 

System V IPC message queue

Post by Andrew Giert » Sun, 11 Nov 2001 09:34:02


 those> they do not work the same.  you can select (or poll) a pipe
 those> but not a message queue (unless you have pselect, which linux
 those> does not).

pselect doesn't have anything to do with message queues; it's the same
as select() but with the addition of a sigset_t parameter for atomically
unblocking signals while waiting (like sigsuspend).

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

1. How/Where do I set the system limits for IPC Message Queues (msgtql, msgmnb, etc)?

Hi:

I'm trying to find out how to set the system IPC limits for
message queues, semaphores, etc.  In solaris, you would set
the following variables (among others) in /etc/system:

        set msgsys:msginfo_msgtql = xxxx
        set msgsys:msginfo_msgmnb = xxxx

Anybody know how to configure this in Linux?

Thanks in advance,

Mark

--
****************************************************************
J. Mark Shacklette
Committee on Social Thought        
University of Chicago


****************************************************************

2. Installing System Commander on a preconfigured dual-boot system ?

3. System function "select( )" and IPC Message Queue

4. S3 TRIO UV+ (86C767)

5. Help on Message Queue (System V IPC)

6. Stealth 64 VRAM -vs- ATI ProTurbo -vs- #9 Motion 771

7. Are UNIX IPC message queues bad?

8. Solaris Perl open file limit 255? Is there a way to get around this?

9. IPC: message queue

10. IPC message queues

11. ipc-message queue problem

12. If a process is blocked in IPC message queue msqid_ds.wwait or rwait ... ...

13. IPC with shared memory and message queues?