关闭时删除命名管道

发布于 2024-11-15 10:08:06 字数 261 浏览 8 评论 0原文

我使用命名管道在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动听の歌 2024-11-22 10:08:06

删除 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.

醉城メ夜风 2024-11-22 10:08:06

我已经很多年没有使用它们了,但我大约 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文