![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with dd command or maybe AFS problem | Anta | Shell Programming and Scripting | 0 | 08-25-2006 07:10 AM |
| SSH Problem auth problem | budrito | UNIX for Advanced & Expert Users | 1 | 03-17-2004 07:12 AM |
| about msgget troble | subrain | High Level Programming | 9 | 12-28-2001 06:52 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Problem with msgget()
Hi,
I am having problem with msgget() function. Here is the problem that I am having on Unix : I have two processes sender and receiver. Sender generates queue (msgget()) with some key e.g. 938, for output. Receiver reads from the same queue. i.e. receiver also tries to get queue id calling msgget() function and using same key, 938 that sender used. But the qid that sender is receiving from msgget() function is 16777219 and receiver is getting different qid. Ideally it should get the same qid i.e. 16777219. I tried to remove this queue using ipcrm –q <qid> And I tried to bring up sender with key as 338. But still it is building qid as such huge number and receiver is getting different qid. Now I am able to read from this queue. But still not sure whether this qid is correct or not Please let me know how do I resove this. Thanks, Ashwini Last edited by Ashwini; 09-14-2006 at 06:54 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
While not extremely experienced in this subject, it strikes me that if the id's were guaranteed to be the identical, they wouldn't need keys to find them.
|
|
#3
|
||||
|
||||
|
test1.c:
Code:
#include<stdio.h>
#include<sys/msg.h>
int main() {
int msqid;
msqid=msgget(938,666|IPC_CREAT);
fprintf(stdout,"msqid from program 1: %d\n",msqid);
fprintf(stdout,"now sleeping for 30 seconds\n");
sleep(30);
msgctl(msqid,IPC_RMID,NULL);
}
Code:
#include<stdio.h>
#include<sys/msg.h>
int main() {
int msqid;
msqid=msgget(938,666|IPC_CREAT);
fprintf(stdout,"msqid from program 2: %d\n",msqid);
msgctl(msqid,IPC_RMID,NULL);
}
In fact, the man page of msgget makes it quite clear: Quote:
So if you have a program that created a message queue with a certain key, then another program that tries to create a message queue with the same key will *always* get the existing message queue id ,unless one of the programs removes the queue from the system. In your case, if you have two programs, is one of the programs removing the message queue before the second one can access it? If this happens, then the queue id associated with your key will no longer exist and you will get a new queue id. And don't worry about the size of the queue id. It makes no difference to your program. |
||||
| Google The UNIX and Linux Forums |