you'r right...
Code:
IN HEADERFILE---------------
#define MSGSIZE 20
struct myMsg {
long mtype;
char mtext[MSGSIZE];
} dataMsg;
SENDER -------------
void mysend(long type, int pid)
{
int msgID;
char msg[MSGSIZE];
dataMsg.mtype = type;
sprintf(msg, "%d", pid);
strncpy(dataMsg.mtext, msg, MSGSIZE);
msgID = msgget(2407, (IPC_CREAT | 0755));
if (msgID >= 0) {
if (-1==msgsnd(msgID, &dataMsg, MSGSIZE, 0)) {
perror("msgsnd");
} else {
printf("PID gesendet: %s \n", dataMsg.mtext);
}
} else {
perror("msgget");
}
}
int main(int argc, char **argv) {
int pid;
mysend(3333,pid);
return 0;
}
RECEIVER---------------
struct myMsg my_msgrcv(long type) {
int msgID;
struct myMsg dataMsg;
long msgTyp = 0;
msgTyp = type;
msgID = msgget(2407, 0755);
if (msgID >= 0) {
if (-1==msgrcv(msgID, &dataMsg, MSGSIZE, msgTyp, IPC_NOWAIT)) {
perror("msgrcv");
} else {
printf("received: %s \n", dataMsg.mtext);
}
} else {
perror("msgget");
}
return dataMsg;
}
int main() {
while(1) {
mymsgrcv(3333);
}
}
The original code is to long, but i only shorten in main. It finally always stucks in the line with the msgrcv cmd.