I have some piece of code which goes like this:
pipe(fd);
child_map[0] = fd[0];
child_map[1] = fileno(stdout)
child_map[2] = fileno(stderr);
pid = fork();
if (child_process)
dup(child_map[0], STDIN_FILENO)
dup(child_map[0], STDOUT_FILENO)
dup(child_map[0], STDERR_FILENO)
execvp(argv[0], argv) /* child process can be either "grep" or "more" etc */
else if parent_process
return;
My problem is, after I redirect the output to grep/more (which can be the child process), I am not able to get the terminal prompt back. The command o/p is printed fine on the terminal though. But I do not get back the prompt and I can see that the "more" or "grep" process is running in the background. I need to enter ctrl+C to get the prompt back. I know it has got something to do with the file descriptors not being closed etc, but I do not know how to resolve this.
This is actually being done from another process context. And I can see that the parent process is still running. It doesn't terminate unless I terminate it. So there isnt any question of the child being orphaned. [hoisted from Vin's comment, clarification value is questionable -msw]