LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-05-2006, 07:12 AM   #1
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
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???
 
Old 03-05-2006, 08:57 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
Old 03-05-2006, 10:21 AM   #3
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Original Poster
Rep: Reputation: 15
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
}
 
Old 03-05-2006, 10:50 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
  


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
POSIX message queues(Solaris) to SYS V message queues(Linux) devershetty Programming 1 01-22-2007 10:15 AM
System V message queues... sachitha Programming 2 03-19-2006 07:12 AM
Posix Message queues? gdipierro Programming 20 07-26-2005 04:59 PM
Message Queues rag_mg Programming 1 05-08-2005 08:00 AM
Message Queues BoldKiller Programming 1 05-28-2003 05:40 PM

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

All times are GMT -5. The time now is 10:37 PM.

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