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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-05-2006, 07:12 AM
|
#1
|
|
Member
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104
Rep:
|
System V message queues shared among processes...
i'm using a system V msg queue. which i created in the main program..
and then there are 4 processes-R a,c,b (child processes of one process)
R sends messages to the msg queue..
i want to make the a, c, b to read the messages..
sending part works, but not the reading
the 'a' process reads mostly junk values..(??)
when i'm sharing a msg queue like that do i have to attach it to a "shared memory segment" or something???
|
|
|
|
03-05-2006, 08:57 AM
|
#2
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Reading and writing from a message queue is conceptually no different from reading or writing from a disk file, a pipe, or a network socket. It's just a stream of bytes: what they mean is entirely up to you.
No, you do not need to set up a shared memory segment. Message Queues ("msgget()") are one type of SysV IPC ("InterProcess Communication" primitive), Shared Memory ("shmget()") is another, Semaphores ("semget()") is yet a third kind of SysV IPC. Using one does not require any of the others; but they can all be used together, in any combination you choose.
Do you have a system where you can experiment with these IPCs yourself (Any *nix system - including Linux - should work fine)?
Otherwise, if you have a Windows system, you might wish to learn about and experiment with the corresponding Windows IPCs.
|
|
|
|
03-05-2006, 10:21 AM
|
#3
|
|
Member
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104
Original Poster
Rep:
|
yes i'm working with Linux Redhat... on this.
i do not understand why i get junk values for the reading process...
when i type ipcs -q , i can see that the messages have gone to the msq queue ,(sent by process R).
//the coding for my reading processes..
void readmsqQ(int qid,struct msgbuf *qbuf)
{
//to read message from the message queue...
struct msgbuf msg;
printf("%d %d \n", qid, sizeof(msg));
msgrcv(qid,(struct msgbuf *)qbuf,sizeof(msg),1, 0);
printf("Type: %d Text:%s %d\n", qbuf->cusNo,qbuf->cus_type ,qbuf->servT);
//this above line prints junk values.. when i manually delete the message queue through the terminal
}
|
|
|
|
03-05-2006, 10:50 AM
|
#4
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Many things *could* be going wrong.
I guess the first step would be to modify your code to check for the return value from "msgrcv()":
Code:
int iret;
iret = msgrcv (...);
PS: Please use "[code]" blocks - it definitely helps!
PPS:
Here's a good tutorial (with sample code):
http://www.ecst.csuchico.edu/~beej/guide/ipc/mq.html
My book on SysV IPC's is undoubtedly out of print, but here's the reference anyway (it's a great book; it's served me well over the years):
Unix System Programming, Keith Haviland & Ben Salama, ISBN 0 201 129191
Last edited by paulsm4; 03-05-2006 at 11:24 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:51 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|