I want to use msgget() to obtain a message queue between two processes, here is my code:
the first one create the mq, the second one open it and add a message to it. But when I execute the second one, I get permission denied. I've already desperately tried everything I can think of to solve this problem. I even manually change the mode of the mq. But all I get is still permission denied. Somebody please help me.....:wall:
struct mymsg
{
long mtype ;
char data[1000] ;
};
int main()
{
int msqid ;
int* nod ;
struct mymsg msg ;
struct msqid_ds msgds ;
key_t key ;
key = ftok("/home/tefino/Documents/APUE_exercise/IPC/ipc",1) ;
perror(NULL) ;
msqid = msgget(key,O_RDWR|IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) ;
perror(NULL) ;
msgctl(msqid, IPC_STAT, &msgds) ;
msgds.msg_perm.mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH ;
msgctl(msqid, IPC_SET, &msgds) ;
msgrcv(fd,&msg, 1000, 0, 0) ;
perror(NULL) ;
printf("%s\n", msg.data) ;
}
struct mymsg
{
long mtype ;
char data[1000] ;
};
int main()
{
int msqid ;
key_t key ;
struct mymsg msg ;
key = ftok("/home/tefino/Documents/APUE_exercise/IPC/ipc",1) ;
gets(msg.data) ;
msqid = msgget(key, O_WRONLY) ;
perror(NULL) ;
struct msqid_ds mds ;
msgctl(msqid, IPC_STAT, &mds) ;
mds.msg_perm.mode = S_IWUSR|S_IRUSR ;
msgctl(msqid, IPC_SET, &mds) ;
msgsnd(msqid, &msg, 1000, 0) ;
perror(NULL) ;
}