The idea is that you'd have a pair of system calls, let's call them create() and start(). create() would create an empty process that would inherit the file descriptors etc. of the parent process, just like fork(), but it would not copy the memory of the parent nor would it start executing, instead it would let the parent execute system calls as if it was the child, for example if the parent called dup2(), it would duplicate file descriptors in the child's file table instead of the parent's. start() would then load the child into memory and cause the child to start executing, like exec(), of course system calls would also return to their usual behavior.
Here is some pseudocode of what this might look like:
Code: Select all
int main()
{
int pipefd[2]
pipe(pipefd);
create(...); //Arguments undecided maybe path and argv?
//Manipulates file descriptors in the child's file table.
close(pipefd[1]);
dup2(pipefd[0], STDIN_FILENO);
close(pipefd[0]);
start(...);
//Back to normal...
return 0;
}