关闭时删除命名管道
我使用命名管道在 Linux 上的 PHP 脚本和 C++ 守护程序之间进行通信。守护进程负责监视管道,在调用脚本时处理命令并生成命令。该系统是一个小型嵌入式设备,它唯一运行的就是 Web 服务器和守护程序。
我应该在程序关闭时删除命名管道,还是可以将其保留在文件系统上?嵌入式设备经常会出现硬关闭的情况,所以即使我在它正常退出时正确关闭它,它在大多数情况下都会留下来。当系统重新启动时打开管道时,管道中是否会出现未知数据?如果是这样,我应该删除它并在每次重新启动时重新制作它,还是太过分了?
I'm using a named pipe to communicate between a PHP script and a C++ daemon on Linux. The daemon sits and watches the pipe, processing commands when the script gets called and generates them. The system is a small embedded device, and the only things it's running are the web server and daemon.
Should I be deleting the named pipe when the program closes, or is it acceptable to leave it on the filesystem? The embedded device often gets hard shutdown, so even if I properly close it when it exits nicely, it'll get left around most of the time anyway. Am I going to end up with unknown data in the pipe when I open it when the system restarts? If so, should I just remove it and remake it every restart, or is that overkill?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除 FIFO 很整洁,但这样做并不重要。特别是,当系统重新启动时,FIFO将被清空。
因此,最好将程序设计为接受 FIFO 的存在,并在缺失时创建它。如果它们完全关闭,那么删除 FIFO 就很好了。
It is neat and tidy to delete the FIFO, but it is not crucial to do so. In particular, the FIFO will be empty when the system is restarted.
So, it is best to design your programs to accept the presence of the FIFO, and to create it if it is missing. If they get closed down cleanly, then removing the FIFO is good.
我已经很多年没有使用它们了,但我大约 80% 确信您可以将节点永远保留在原处。它们在启动时将为空,因为数据保存在内核数据结构中。
I haven't used them for years, but I am about 80% sure you can leave the nodes in place forever. And they'll be empty on bootup, because the data is held in kernel data structures.