找到 pipe() 时如何停止读取 pipe() ''

How to stop reading pipe() when '' is found

本文关键字:pipe 何停止 找到 读取      更新时间:2023-10-16

我在使用 read((和停止 read(( 时遇到问题。这是我的代码:

char buffer[15];
char value[15] = {'1'};
long m = 1;
write(pipeA[1], value, strlen(value) + 1);
close(pipeA[1]);
cerr << "The parent process is ready to proceed.n";
cerr << "Parent: t Value: " << value << endl;
while(m > -999999999 && m < 999999999)
{
while (read(pipeA[0], &buffer, 1) > 0)
{
cerr << "Testn";
}
m += 200 - 3 * m;
}

close(pipeA[0]);

我的问题是如何在空字符"\0"处停止对缓冲区的读取

我想通了,在执行这个函数之前,我正在关闭我的写管道。