What is the proper place to put named pipes on Linux?
Asked Answered
M

2

10

I've got a few processes that talk to each other through named pipes. Currently, I'm creating all my pipes locally, and keeping the applications in the same working directory. At some point, it's assumed that these programs can (and will) be run from different directories. I need to create these pipes I'm using in a known location, so all of the different applications will be able to find the pipes they need.

I'm new to working on Linux and am not familiar with the filesystem structure. In Windows, I'd use something like the AppData folder to keep these pipes. I'm not sure what the equivalent is in Linux.

The /tmp directory looks like it probably could function just nicely. I've read in a few places that it's cleared on system shutdowns (and that's fine, I have no probably re-creating the pipes when I start back up.) but I've seen a few other people say they're losing files while the system is up, as if it's cleaned periodically, which I don't want to happen while my applications are using those pipes!

Is there a place more suited for application specific stores? Or would /tmp be the place that I'd want to keep these (since they are after all, temporary.)?

Meritorious answered 3/4, 2013 at 18:4 Comment(0)
M
10

I've seen SaltStack using /var/run. The only problem is that you need root access to write into that directory, but let's say that you are going to run your process as a system daemon. SaltStack creates /var/run/salt at the installation time and changes the owner to salt so that later on it can be used without root privileges.

I also checked the Filesystem Hierarchy Standard and even though it's not really important so much, even they say:

System programs that maintain transient UNIX-domain sockets must place them in this directory.

Since named pipes are something very similar, I would go the same way.

Misfeasance answered 7/9, 2013 at 19:37 Comment(1)
I apologize for not seeing your answer earlier, but this is exactly the kind of response I was looking for. I wasn't aware of the 'Filesystem Hierarchy Standard', and apparently that's got all sorts of information goodies for a fledgling Linux developer like myself. In addition to /var/run, it seems /var/tmp is also acceptable for my use case, since it preserves those through reboots, too. Again, thanks a bunch!Meritorious
U
5

On newer Linux distros with systemd /run/user/<userid> (created by pam_systemd during login if it doesn't already exist) can be used for opening up sockets and putting .pid files there instead of /var/run where only root has access. Also note that /var/run is a symlink to /run so /var/run/user/<userid> can also be used. For more infos check out this thread. The idea is that system daemons should have a /var/run/<daemon name>/ directory created during installation with proper permissions and put their sockets/pid files in there while daemons run by the user (such as pulseaudio) should use /run/user/<userid>/. Another option is /tmp and /var/tmp.

Unpeople answered 21/12, 2015 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.