Unix FIFO in go?

2020-08-15 07:29发布

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?

标签: unix go pipe fifo
2条回答
劫难
2楼-- · 2020-08-15 08:23

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

查看更多
唯我独甜
3楼-- · 2020-08-15 08:29

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.

查看更多
登录 后发表回答