ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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???
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.
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
}
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.