Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Mac OS阻止读取(POSIX)_Macos_Posix_Blocking - Fatal编程技术网

Macos Mac OS阻止读取(POSIX)

Macos Mac OS阻止读取(POSIX),macos,posix,blocking,Macos,Posix,Blocking,我尝试组织使用classic scheme fork()/pipe()处理的父子之间的阻塞传输, 但我不明白为什么只有child中的first read()是阻塞的,而所有后续的读取都不是,而且读取后返回的结果不是零 例如: 父级,首先将文件名写入子级,然后等待回答: for (NSString* file in filenames) { fprintf(pict_log, "send to conversion file %s\n", filename);

我尝试组织使用classic scheme fork()/pipe()处理的父子之间的阻塞传输, 但我不明白为什么只有child中的first read()是阻塞的,而所有后续的读取都不是,而且读取后返回的结果不是零

例如:

父级,首先将文件名写入子级,然后等待回答:

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);
}
孩子,相同,但反之亦然

while(!g_break_child) 
{
            memset(filename, ' ', 512);
            int read_bytes = read(g_pfds[0], filename, 512);
            // some processing...
            write(g_pfds[1], filename, 512);
        }

每次迭代后,我都应该在child的read()上被阻止,但为什么没有发生呢?

现在我可以回答自己,问题是:
在我的例子中,我需要双向传输,但是当我们通过pipe()func打开两个描述符时,我们就创建了单向通道,在双向传输的情况下,我们需要调用pipe()两次来创建两个单向管道

现在我可以回答自己,问题是: 在我的例子中,我需要双向传输,但是当我们通过pipe()func打开两个描述符时,我们就创建了单向通道,在双向传输的情况下,我们需要调用pipe()两次来创建两个单向管道