我有以下打开的 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/