Unix FIFO in go?

2020-08-15 07:26发布

问题:

Is there any way to create a unix FIFO with Go language? There is no Mkfifo, nor Mknod in os package, though I expected named FIFOs are largely used in posix OS's. In fact, there is a function for creating an unnamed FIFO (pipe), but no function for creating named pipes.

Am I the only one who needs them?

回答1:

In order to get it to work on Linux, I simply did a

syscall.Mknod(fullPath, syscall.S_IFIFO|0666, 0)

It seemed to do the trick.

Here is a reference for the underlying mknod() call



回答2:

There is a Mkfifo, but it's in the syscall-package :)

Searching through the source gives me the feeling it's not available on anything but OS X and FreeBSD though: http://www.google.com/codesearch#search&q=Mkfifo+package:http://go%5C.googlecode%5C.com

I don't have a unix machine ready to test with. You can use cgo if you like to build a C-interface package which exports it for you.



标签: unix go pipe fifo