12

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?

zserge
  • 2,212
  • 2
  • 31
  • 40

2 Answers2

13

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

laslowh
  • 8,482
  • 5
  • 34
  • 45
3

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.

Skurmedel
  • 21,515
  • 5
  • 53
  • 66
  • Thanks! And you are right, on linux it says: `undefined syscall.Mkfifo`. So, will wait for linux support. – zserge Jun 23 '11 at 07:22
  • 1
    Just to update this, [`syscall.Mkfifo`](https://golang.org/pkg/syscall/#Mkfifo) (and [`unix.Mkfifo`](https://godoc.org/golang.org/x/sys/unix#Mkfifo)) now exist for most OSes supported by Go (the notable exceptions are windows and plan9). Also, using `syscall` or `golang.org/x/sys/unix` (with appropriate build constraints) should be preferred over `cgo`. – Dave C Jun 03 '19 at 13:23