RedPeasant
RedPeasant

Reputation: 544

Deleting Named Pipes When Closing

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?

Upvotes: 3

Views: 3298

Answers (2)

jcomeau_ictx
jcomeau_ictx

Reputation: 38492

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.

Upvotes: 0

Jonathan Leffler
Jonathan Leffler

Reputation: 754860

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.

Upvotes: 6

Related Questions