IPC Message Queue. msgrcv doesnt work..

Hi everybody,

this is the situation. there is a programm XYZ which opens a message queue with the key 47110815 and waits for a SIGUSR1. After receiving this signal it sends a message with type 100 and a number (as ASCII) in the message-body.

I have to write a prog which frist sends the SIGUSR1 to that process XYZ and receives the message which XYZ loaded in the message queue. After that it has to send a message (with type = the number in the messagebody). After receiving my message XYZ will modify it and load it again in the message queue. I have to read that modified message again. I've written the code but it hangs up at the line where it should receive the message (msgrcv) for the first time.

executing XYZ will display its pid. we will start my prog with that pid as parameter and will use it to send SIGUSR1 to XYZ.

I cant view XYZ but can ensure that it works, cuz its from our proffessor.. It'd be great if onyone could help. Here is my code:

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#define KEY 47110815
#define MSIZE 100

struct message{
long type;
char data[MSIZE];
};

struct message m;

main(int i, char *p[]){
int id;
long number; char s[100];

kill(atoi(p[1]),10); //sends SIGUSR1 to process XYZ
printf("\nSIGUSR1 sent!\n");
id=msgget(KEY,0666 );

printf("Waiting for 1. Message from XYZ...\n");
msgrcv(id,&m,MSIZE,(long)100,0);
printf("Message received!\n");

number = m.type = (long) atoi(m.data);
strcpy(&m.data[0],"abcde");
msgsnd(id,&m,MSIZE,0);
printf("Message sent with Typ=%d Id=%d\n",m.type,id);

printf("Waiting for changed Message...\n");
sleep(0.5);
msgrcv(id,&m,MSIZE,(long)number,0);
printf("Changed Message received!:");
printf(">>%d>>%s\n",m.type,m.data);
}

Please no not post homework in the main Forums. Thread closed.