将fmemopen ed文件描述符设置为子进程的标准输入 [英] Setting a fmemopen ed file descriptor to be the standard input for a child process

查看:82
本文介绍了将fmemopen ed文件描述符设置为子进程的标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux中有一个fmemopen文件描述符(指向父缓冲区),我希望能够在C语言中将此文件描述符设置为子进程的标准输入(我不为此目的)可以访问代码)

I have an fmemopen file descriptor(pointing to a buffer in the parent) in Linux and I would like to be able to, in C, set this file descriptor as the standard input for a child process(for whom I do not have access to the code)

这可能吗?如果是这样,我该怎么办?我希望尽可能避免写入磁盘.

Is this possible? If so how do I do it? I would like to avoid having to write to disk if at all possible.

推荐答案

这是不可能的.继承stdin/out/err完全基于文件描述符,而不是stdio FILE流.由于fmemopen不会创建文件描述符,因此它不能成为新进程的stdin/out/err或以任何方式用于进程间通信.您正在寻找的是管道,除非需要查找,在这种情况下,您需要一个临时文件. tmpfile函数可用于创建一个,而不必担心在文件系统中创建一个可见的名称.

This is not possible. Inheriting stdin/out/err is based purely on file descriptors, not stdio FILE streams. Since fmemopen does not create a file descriptor, it cannot become a new process's stdin/out/err or be used for inter-process communication in any way. What you're looking for is a pipe, unless you need seeking, in which case you need a temporary file. The tmpfile function could be used to create one without having to worry about making a visible name in the filesystem.

这篇关于将fmemopen ed文件描述符设置为子进程的标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆