c - Receiving SysV messages using fork() -


i'm trying receive series of messages sent msgsnd in series of fork()s. can tell messages sent ok, receiving them has been problem. here's problem part of code, using 3 messages example:

for(j=1;j<4;j++) {     if(!(pid_a = fork()))     {         msglen = msgrcv(msqid, &rec, sizeof(struct u_msgbuf) - sizeof(long), 0,0);         if(msglen == -1)         {             printf("%i - %s.\n", j, strerror(errno));             exit(0);         }         else         {             printf("%i - %s.\n", j, rec.word);             exit(0);         }     } } 

if write code similar without fork(), works fine, know fork() messing message queue in way don't understand. tell me why won't work in fork(), , how code in such way fork() receive messages properly?

edit: getting this: first fork process runs fine, second does, third fails. errno getting set 22, invalid argument.


update (declarations used):

struct u_msgbuf {   long mtype;   char word[15]; };  struct u_msgbuf rec;  


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -