Various manual pages commonly exemplify FIFOs being opened in the /tmp
directory, but they do not share a common naming convention. When I list the contents of my /tmp
dir' I get nothing but directories named like /tmp/ssh-5oRuBPhI9lv9
. Is there a convention, especially/specifically for IPC?
There is no official naming convention.
Sure, when using FIFOs, you will need some convention, since FIFOs are typically used for process communication between unrelated processes. So the name must be known to the different processes, which implies you have to follow some sort of convention, but it's your call.
The reason you see directories and files with mysterious names in /tmp
is usually the result of the corresponding processes calling mkstemp(3)
or mkdtemp(3)
. These functions atomically generate a unique name and create the corresponding file / directory.
If for some reason you want your FIFO to have a similar name, you can generate a unique name with tmpnam(3)
and then pass that name to mkfifo(3)
. But note that there is a window of time between the call to tmpnam(3)
and the call to mkfifo(3)
where another process could create a file with the same name (and then mkfifo(3)
would fail). If that's a problem, you could instead atomically create a temporary directory with mkdtemp(3)
and then create the FIFO inside that directory with a name of your choice.
The reason there is no sure way to atomically generate and create a temporary, uniquely named FIFO is that FIFOs are used as rendezvous points for unrelated processes, so in general the name must be known a priori. Having a FIFO with a unique temporary name would make it harder for other processes to find it, which kind of defeats the purpose.