LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Posix Message queues? (https://www.linuxquestions.org/questions/programming-9/posix-message-queues-344932/)

gdipierro 07-20-2005 05:23 AM

Posix Message queues?
 
Where can I find Posix Message Queues?

I am running Red Hat Linux with the libgcc.a date being feb of 2003.
Is mqueue.h supposed to be there or is it in a later release?

Thanks.

deiussum 07-20-2005 10:34 AM

I don't think they are technically POSIX message queues, but try looking at 'man msgget' and 'man msgsnd'

rstewart 07-20-2005 10:51 AM

Hello,

I'm not sure about your Linux release, but mqueue.h exists in /usr/include on my Fedora Core 3 based system. I am also able to man the various mq_* functions so I know that the POSIX message queues are supported.

gdipierro 07-22-2005 07:46 AM

Thanks,
I found that I need glibc 2.3.4 (after 4/12/04). This RH 9 dist dated 2/2003 needs to be updated. I guess I either need fedora or RH enterprise.

rstewart 07-22-2005 10:24 AM

Cool, glad that you were able to solve your problem. I am enjoying FC3. It seems to be very stable in the machines that I have installed it on (3 completely different systems, plus others that people at work are using). My work is "targeting" FC3 as the "recommended" distro for all of our Linux based server products.

Good luck with your project!

jfitzger68 07-22-2005 04:56 PM

I have FedoraCore 4 and I cannot find library support for the POSIX message queues. I know I have mqueue.h and I can link with the pthread library, but I cannot even find any documentation on which library the message queue services are in....

Josh Sandeman
San Francisco

rstewart 07-22-2005 05:01 PM

jfitzger68, what happens if you "man mq_open"? On FC3 I get the man page for the POSIX message queue open function.

jfitzger68 07-22-2005 05:08 PM

I get the man pages for all of the POSIX functions, and all of the include files are present where they should be. Now, to use threads someone explained to me that I need to explicitly include the pthread library using the gcc switch -lpthread, but this obviously does not include the mqueue functions as I get link errors for those. But I cannot find any reference on the Internet to which library those are contained in!

rstewart 07-25-2005 04:13 PM

jfitzger68, I found the POSIX message queue functions for my FC3 based system. They are in /usr/lib/librt.* So, just adding -lrt to your link step should get them included. Try it and see what happens. BTW: libpthread is only good for the POSIX threads library, not the POSIX message queues.

jfitzger68 07-25-2005 04:22 PM

Aha! That worked like a champ! Thanks so much for your help!

Josh

rstewart 07-25-2005 04:26 PM

Cool! Glad to have helped!

So how is the weather up in the city? It is HOT down here in San Jose, and the building's air conditioner is on the fritz :mad:

jfitzger68 07-25-2005 04:34 PM

It's not too bad up here... mid to upper 70s, I'd say. Sorry to hear you are roasting down in SJ. I'm not a heat person, myself. Cool Autumn days in New England is my favorite weather.

rstewart 07-25-2005 04:42 PM

Yup, I remember (I grew up in Conn). You could taste Autumn in the air when is was just cool enough, but not too cold yet.

Ciao!

jfitzger68 07-25-2005 06:08 PM

Sorry to bug you again. My program compiles and links, yet I get a "permission denied" runtime error when attempting to create a message queue. This happens even when I am running the program as root. None of the code examples I have seem do anything special and look pretty much like mine. Any ideas?

rstewart 07-26-2005 09:43 AM

Sorry, but my knowledge of POSIX message queues is many, many years old. The last time that I attempted to use POSIX message queues was when I was writing a real-time embedded application running on top of QNX. I needed a message queue mechanism and all they supported was the POSIX message queues. The implementation used disk files as the actual queue mechanism, and I needed to run in a read-only DOC type of system, so I was forced to write my own RAM based message queue system...

Why don't you post your relevant open/creation code and I will see if anything seems obvious to me.

jfitzger68 07-26-2005 10:59 AM

Okay, here it is. These are the declarations:

typedef struct {
long type;
cmd_types command;
state_types state;
char description[80];
} SmartHubMessage_T;

#define PROJECTOR_INBOX_SIZE 16
#define PROJECTOR_INBOX_FLAGS 0
const char PROJECTOR_INBOX_NAME[] = "/home/josh/hack/projQ";
struct mq_attr projInboxAttr;
mqd_t projectorInboxId;

And here's the code:

projInboxAttr.mq_maxmsg = PROJECTOR_INBOX_SIZE;
projInboxAttr.mq_msgsize = sizeof(SmartHubMessage_T);
projInboxAttr.mq_flags = PROJECTOR_INBOX_FLAGS;
projectorInboxId = mq_open(PROJECTOR_INBOX_NAME, O_CREAT|O_RDWR|O_EXCL, S_IRWXU, &projInboxAttr);
if (projectorInboxId == (mqd_t)-1) {
perror("\nSmartHub");
exit(-1);
}

Thanks!

rstewart 07-26-2005 12:09 PM

Well, I've done some testing using my FC3 based system and I have to tell you - I am still not impressed with POSIX message queues...:confused:

After looking at the behavior of a test program based upon your code snippets, along with the man pages, I think that when the man pages claim "implementation-defined" they mean "bug". What I eventually got to work was to use a message queue name of "/msgQ" (without any other path information). Also, I had to run the executable test program as root, running as a lowly user just error-ed out even if I granted all read/write/search permissions to the root "/" directory.

I hope that this helps you, it may not be the best solution but it looks like it should work for you as a workaround unless some other brave and knowing person can offer more insights. :D

jfitzger68 07-26-2005 12:26 PM

Thanks so much for looking at this.

In the end this application will run under the eCos Real-Time OS, and I can only hope that the implementation there will be more straightforward. I had hoped to develop the app under Linux to control for the complexities of the OS and focus more on the base application logic, bus alas it seems this is not to be. :(

Anyhow, I'll try your solution. Thanks so much once again.

jfitzger68 07-26-2005 12:38 PM

Your solution worked! UNIX is a strange world sometimes.

rstewart 07-26-2005 12:46 PM

Congratulations!

Good luck on the RTOS implementation. IMHO real-time embedded work is much more fun than "conventional" programming. Real-time; nice compact ,tight, and efficient organized chaos. :p

jfitzger68 07-26-2005 04:59 PM

I agree. I am a huge fan of efficient, compact chaos.


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