You mentioned fifo, aka a named pipe, so we'll look at that. (code here assumes *nix):
This quick example shows sending data from the parent to the child, having the child manipulate it, then returning it to the parent. So you're not "passing" the fifo, but each process (or child process) will have access to the char *
which gives them the name of the fifo so they can open it for reading or writting as they need to. You can take this concept and expand upon it for each of the children nodes you have:
int main()
{
int fd, n, ret;
fd_set rfds;
char * myfifo = "/tmp/myfifo";
mkfifo(myfifo, 0666); // Create this buffer
if(fork()) //Kid code
{
char kid_buffer[4] = {0};
char temp;
fd = open(myfifo, O_RDONLY); //Open the fifo for reading
n = read(fd, kid_buffer, 4);
printf("Kid %d read %d bytes, parent gave us %s\n",getpid(), n, kid_buffer);
fflush(stdout);
close(fd);
// "sort" the data the parent gave us
temp = kid_buffer[0];
kid_buffer[0] = kid_buffer[1];
kid_buffer[1] = kid_buffer[2];
kid_buffer[2] = temp;
kid_buffer[3] = '\0';
printf("Kid %d reoriginized the list %s\n",getpid(), kid_buffer);
fflush(stdout);
// send the data back
fd = open(myfifo, O_WRONLY);
write(fd, kid_buffer, strlen(kid_buffer));
close(fd);
return 0;
}
else
{
char arr[] = "abc";
//Open the fifo for writing
fd = open(myfifo, O_WRONLY);
write(fd, arr, strlen(arr)); //Sent my data to kid
printf("Parent process %d, just sent my data %s to the kid\n", getpid(), arr);
fflush(stdout);
close(fd);
//Open the fifo for reading
fd = open(myfifo, O_RDONLY);
n = read(fd, arr, 4);
// show the data we got back
printf("Parent %d read %d bytes, kid gave us back %s\n",getpid(), n, arr);
fflush(stdout);
close(fd);
}
unlink(myfifo);
return 0;
}
So from the output here you can see the parent created it's own array "abc" and it got modified by the child (passed via FIFO) to "bca", now it's back with the parent and formated.
mike@linux-4puc:~> ./a.out
Parent process 4295, just sent my data abc to the kid
Kid 4294 read 3 bytes, parent gave us abc
Kid 4294 reoriginized the list bca
Parent 4295 read 3 bytes, kid gave us back bca