go - 如何在golang中写入已经打开的FD

标签 go pipe fifo

我有以下打开的 FD(lsof 输出):

auth    11780 root    5w  FIFO               0,10      0t0  72061824 pipe

我需要在 FD 5 (FIFO) 中写一些东西。在 C 中,它由系统调用 write() 执行:

19270 write(5, "*************", 12 <unfinished ...>

提前致谢!

最佳答案

使用os.NewFile通过文件描述符“打开”现有文件:

func NewFile(fd uintptr, name string) *File

NewFile returns a new File with the given file descriptor and name.

file := os.NewFile(5, "pipe")
_, err := file.Write([]byte(`my data`))
if err != nil {
    panic(err)
}

关于go - 如何在golang中写入已经打开的FD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44886135/

相关文章:

go - 为什么我在添加两个正 16 位整数后得到负整数?

go - 了解 Go channel 死锁

Golang 反射 : passing a sturct member variable to a function and return its tag name

c - 退出程序后输出执行UNIX命令

c - 先进先出执行流程系统

go - vim 去 : how to see the log of :GoTestFunc -v?

C 程序模拟命令行提示符

c - 在Linux中无法阻止从命名管道(FIFO)读取

linux - 如何从管道文件中返回?

c - 带/dev/urandom 的 FIFO