From the GNU manual:
The vfork() function has the same effect as fork(2), except that the behavior is undefined if the process created by vfork() either modifies any data other than a variable of type pid_t used to store the return value from vfork(),
What does it mean? Does it mean the return value of vfork() cannot be assigned to a non-pid_t type variable?
The manual is quite confusing on this. Actually, both processes (the child and the father) shared the same address space, even the stack!
vfork()returns twice:The return code of
fork()/vfork()is typically stored in a variable (of typepid_tto follow the synopsis of the system calls):As the address spaces are shared between the father and the child when we are running
vfork(), the same variable is modified in both the father and the child! But it is set sequentially to 0 in the child process and after the latter either exits or executes a program, the variable is set a second time but with the child's pid in the father process.NB: The manual says: