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
Post a Comment