Reputation: 1
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?
Upvotes: 0
Views: 127
Reputation: 5221
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 type pid_t
to follow the synopsis of the system calls):
pid_t pid = vfork();
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:
vfork() differs from fork(2) in that the calling thread is suspended until the child terminates (either normally, by calling _exit(2), or abnormally, after delivery of a fatal signal), or it makes a call to execve(2).
Upvotes: 0