c++管道:是否等待写入
我使用管道在进程之间进行通信。当我写入管道时,读取速度比写入速度慢,write() 会阻塞直到可以原子写入管道吗?
I use pipes to communicate between processes. When I write to a pipe, and I read it slower than I write, will write() block until the atomic write to the pipe is possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,至少在写入的字节数小于保证为原子的字节数的情况下。
Yes, at least if the number of bytes being written is smaller than the number guaranteed to be atomic.
write() 不需要写入所有传递的数据 - 它可以写入更少的数据,并且您必须检查实际写入了多少数据。
write()
is not required to write all the data passed - it can write less and you have to check how much has actually been written.符合 POSIX 的系统应该阻塞。
来自 write(2) 手册页:
“POSIX 要求可以证明在 write() 返回后发生的 read(2) 返回新数据。请注意,并非所有文件系统
符合 POSIX 标准”
A POSIX conform system should block.
From the write(2) manpage:
"POSIX requires that a read(2) which can be proved to occur after a write() has returned returns the new data. Note that not all file systems
are POSIX conforming"