LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2012, 09:42 AM   #1
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Rep: Reputation: 24
Unhappy why does message queue does not have poll/select like mechanism


Like we can do, poll/epoll/select on an fd, we can not on msg queue id. I found some non standard methods to make msgqueue-id to fd, but afterall its a non standard. So my question is, Why linux geeks, not implemented poll/select on msg queue id ? Does that lead to serious issue ?

I need to implement such sort of mechanism. How can I do that ?
 
Old 04-06-2012, 11:14 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I think we have to assume that if it were feasible, it would have been done by now. It is probably a case where the API seems to resemble the file-descriptor case, but the underlying mechanisms are sufficiently different that it is difficult or impossible to implement. Just my guess.
--- rod.
 
1 members found this post helpful.
Old 04-06-2012, 09:14 PM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by vdx View Post
Like we can do, poll/epoll/select on an fd, we can not on msg queue id.
msgget() et al. is part of System V IPC, which dates back three decades. For all practical intents and purposes, it is fixed in stone; any change, however small, is likely to break a large number of installed programs. We don't do that.

Quote:
Originally Posted by vdx View Post
Why linux geeks, not implemented poll/select on msg queue id ?
Well, non-Linux banal person, because you should use POSIX message queues instead, because their interface is better. In Linux, a POSIX message queue is a file descriptor. See the end of man 7 mq_overview for details.

If you need to use poll, epoll, or select with a System V message queue, even in portable code, create a socket pair, and either a thread or a child process. Have the thread/child block in a call to msgrcv(id, &dummy_msgbuf, 0, 0, 0). As the length is zero, it will not read the message. Whenever the call returns, have the thread/child issue a one-byte write to the socket, then a one-byte read, and finally call msgrcv() again. Continue until the message queue is closed, or the socket is closed. (Close the other one, too, and return (if thread) or exit (if child process). That way the main process does not need to worry about it after creating it; the thread/child will clean itself up when it is no longer needed.)

In your poll/epoll/select routine, when the socket becomes readable, receive the messages in a loop using msgrcv(,,,,IPC_NOWAIT), until the return value is -1 with errno==ENOMSG. Write one byte to the socket, and your message queue has been serviced.

This approach should need only about a hundred lines of clean C to implement. Since the thread/child process will be sleeping all the time, it will not consume any significant CPU time. It also needs very little memory, because it does not read the actual messages, and it only sends and receives single bytes via the socket. The "cost" of this approach is minimal.

It rather seems to me you have decided you want to use one specific approach, and are wailing because we don't see how superior that approach would be. The reality is, you have multiple possibilities and avenues to solving whatever your underlying problem might be. You even have a nice workaround to the perceived "lack". Now, go code!

Hope this helps,

Last edited by Nominal Animal; 04-09-2012 at 05:36 AM. Reason: Fixed end tag
 
1 members found this post helpful.
Old 04-08-2012, 10:59 PM   #4
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Original Poster
Rep: Reputation: 24
thnx, Nominal Animal, It was very very useful.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible for me to write in front of queue in case of message queue? hemanthv414 Linux - Newbie 1 11-17-2008 04:40 PM
Differance Between Select ( ) and Poll ( ) dina3e Linux - Server 5 09-02-2008 08:34 AM
Emulator for POLL SELECT Jose Rivas Fedora 2 01-22-2007 08:01 AM
poll/select in tty driver metso777 Linux - Kernel 0 11-13-2006 09:57 AM
select/poll and Signal Safety nopcoder Programming 9 01-30-2006 07:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration