when i open my computer and run this program first ,the answer always is "Invalid argument" .
use ipc to see the queue stat, i found a queue is already exist just like this
"Message Queues
q 0 0x00000835 --rw-rw-rw- iccard informix
"
when i delete the queue ,and restart my program ,everything right.
so why? please tell me.
thank you.
It may be because you are not deleting the "Message Queue" before exiting your application. You should be using the command IPC_RMID in your shmctl\(\) function to remove the Message Queue before exiting your program.
Are you sure you are getting the Error Message "Invalid argument" for this msgget()? Maybe the error is on some other function like: msgctl() or msgsnd() or msgrcv() . . .
I dont see any error in the code pasted above, though I still think the error is somewhere else! Why dont you paste the whole program, we'll hopefully solve the problem.
/* this is the function body about openMsg /
int openMsg( key_t k )
{
int iRtn;
key_t key;
char sFilePath[200];
if( k == 0 ){
/ if k is zero , get key by a file */
sprintf( sFilePath,"%s/MSG_ERR_ID",getenv("CNF_PATH") );
key=ftok(sFilePath,'@');
if( key < 0 ){
errorlog("%s.[%s,%d]",strerror(errno),__FILE__,__LINE__);
return -1;
}
}
else{
key = k;
}