Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix FIFO in go?

Tags:

unix

pipe

go

fifo

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?

like image 674
zserge Avatar asked Jun 22 '11 14:06

zserge


People also ask

What is the FIFO in Unix?

A FIFO special file (a named pipe) is similar to a pipe, except that it is accessed as part of the filesystem. It can be opened by multiple processes for reading or writing. When processes are exchanging data via the FIFO, the kernel passes all data internally without writing it to the filesystem.

What are FIFO files in Linux?

A FIFO special file sends data from one process to another so that the receiving process reads the data first-in-first-out (FIFO). A FIFO special file is also called a named pipe, or a FIFO . A FIFO special file can also be shared by a number of processes that were not created by forks.

How do you make a FIFO?

We can create a FIFO from a program using the mkfifo system call. #include <sys/stat. h> int mkfifo (const char *path, mode_t perms); // Returns -1 on error. A FIFO can be opened using the open system call.

Are pipes FIFO?

A pipe is a mechanism for interprocess communication; data written to the pipe by one process can be read by another process. The data is handled in a first-in, first-out (FIFO) order. The pipe has no name; it is created for one use and both ends must be inherited from the single process which created the pipe.


2 Answers

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

like image 117
laslowh Avatar answered Sep 28 '22 17:09

laslowh


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.

like image 38
Skurmedel Avatar answered Sep 28 '22 16:09

Skurmedel