I try to organize blocking transfer between parent-child processed using classic scheme fork()/pipe(),
but I coudn’t understand why only first read() in child is blocking, but all subsequent reads are not, and besides that they returns not zero result after read!
for example:
parent, first write filename to child, than wait for answer:
for (NSString* file in filenames) {
fprintf(pict_log, "send to conversion file %s\n", filename);
write(g_pfds[1], filename, 512);
memset(filename, ' ', 512);
read(g_pfds[0], filename, 512);
fprintf(pict_log, "completed for file: %s\n", filename);
}
child, the same but vice versa.
while(!g_break_child)
{
memset(filename, ' ', 512);
int read_bytes = read(g_pfds[0], filename, 512);
// some processing...
write(g_pfds[1], filename, 512);
}
I should be blocked on child’s read() after each iteration, but why this doesn’t happened?
Now I could answer to myself, problem is:
in my case I need bidirectional transfer, but when we open couple of descriptors through pipe() func, we thus create unidirectional channel, in case bi-directional transfer we need call pipe() twice to create two unidirectional pipes!