I am a newbie in System Programming and I encounter some misunderstanding in fork and vfork.
So here comes the problem:
Because it's common to redirect stdin
and/or stdout
before calling exec
in the child process. If they shared the same file descriptor table, this would modify the parent process's I/O.
You shouldn't store any variables in the child process. vfork()
should only be used if you're going to immediately call an exec
function.
Note that vfork()
is obsolete on modern operating systems. Instead of copying the address space they use copy-on-write.
For more information see What is the difference between fork() and vfork()?