The child process, AFAIK, is just an exact copy of the parent process. So when you
fork(), you're just recreating your process. I'm not sure where execution begins in the child process - I would assume, from the instruction directly after the fork, otherwise the process would keep forking ad infinitum and you'd have some kind of weird process overflow or something - but anyway, you can use stdout, stdin and stderr, just as you usualy would.
I'm not sure what your asking (although it's likely my knowledge doesn't stretch this far... very likely, in fact, as I didn't know what forking was three weeks ago...); it seems like you want to know whether you can have a child running without interaction from anything else. You can - fork() returns the PID of the process that was forked. If the PID is 0, you have the child process. If the PID is > 0 you have the parent process. If it's -1, then you have an error...
Consider the following:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
pid_t PID = fork();
switch (PID) {
case -1:
std::cerr << "Error!\n"
break;
case 0: // This is the child process
std::cout << "Success! Child process created.\n";
break;
default: // Parent process
std::cout << "PID: " << PID << "\n";
break;
}
|
The output of that would be one of the following:
1.
Success! Child process created.
PID: 2 |
2.
PID: 2
Success! Child process created. |
3.
I'm not sure what you're asking though; maybe someone else knows better.