0

I have created an application that launches a couple of child processes using fork and execv.

string process;  //initialized before execv call
char** process_args;  //initialized before execv call
int pid = fork();
if(pid == 0) {
    execv(process.c_str(), process_args);
}

The processes launch, but they block the parent's access to STDIN until every child exits. I would like the parent process to have access to STDIN while the child processes are still running.

Is this possible, and if so - how? I don't have to use execv. The processes don't really need to have any notion of each other once they are launched.

Thanks!

zsalzbank
  • 9,685
  • 1
  • 26
  • 39

1 Answers1

0

Close the child's STDIN before exec*().

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 1
    I tried only closing `STDIN`, but found that I had to close all the streams (`IN`, `OUT` and `ERR`) in order for the console of the parent not to be blocked. Any idea why this is? Also, when the parent process is closed now, the child process is not killed, but it was before. Why does that happen? Thanks! – zsalzbank Mar 18 '12 at 16:53