The vfork can change variables in parent process, but why can't it increase the stack?
void f1()
{
vfork();
}
f2() leads to the crash.
void f2()
{
char buf[100];
}
int main()
{
f1();
f2();
_exit(0);
}
If I change vfork() to fork(), the crash won't happen.
The only thing you're allowed to do after calling vfork()
is execute a file. It's right in the documentation:
The
vfork()
function shall be equivalent tofork()
, except that the behavior is undefined if the process created byvfork()
either modifies any data other than a variable of type pid_t used to store the return value fromvfork()
, or returns from the function in whichvfork()
was called, or calls any other function before successfully calling_exit()
or one of theexec
family of functions.... > The use of
vfork()
for any purpose except as a prelude to an immediate call to a function from theexec
family, or to_exit()
, is not advised.
To wit, the only legal calls are _exit
and exec*
.