Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a fmemopen ed file descriptor to be the standard input for a child process

Tags:

c

linux

pipe

mmap

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.

like image 923
user439407 Avatar asked Oct 28 '25 20:10

user439407


1 Answers

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.

like image 199
R.. GitHub STOP HELPING ICE Avatar answered Oct 30 '25 12:10

R.. GitHub STOP HELPING ICE