There's not a direct way to get the child pid as for the parent pid
fork() returns one of three values: child pid, 0, and
- child pid is returned to the parent.
- 0 is returned to the child in the parent's code.
- -1 is returned when the
fork() had error(s).
... so you already have the child(rens) pid(s) before and after they
fork(). If you want the child pid after
for example, the easiest way is to just hang on to it when it is returned
fork(), i.e.; store it.
If that's not efficient enough for you there's the possibility, as a
commenter commented, you could set up a
pipe() or two for
communicating it back to the parent.
io is in;
io is out. You would use