clone(CLONE_VFORK) behavior
David Wuertele
dave+libc-help@wuertele.com
Tue Jun 30 19:02:00 GMT 2009
The man page for clone() says:
If CLONE_VFORK is set, the execution of the calling process is
suspended until the child releases its virtual memory resources via a
call to execve(2) or _exit(2) (as with vfork(2)).
Here's a test program that behaves differently from what this man page
leads me to expect:
#include <sys/wait.h>
#include <sched.h>
#include <unistd.h>
#include <stdio.h>
int
clonefunc (void *data)
{
sleep(1);
fprintf (stderr, "got b\n");
_exit(0);
}
int
main (int ac, char *av[])
{
char *child_stack[16384];
clone (clonefunc, child_stack, CLONE_VFORK|SIGCHLD, NULL);
fprintf (stderr, "got a\n");
return 0;
}
I expect this to pause for one second, then print "got b" followed by
"got a". But on my RHEL4 system (i686/linux-2.6.9/glibc-2.3.4), it
immediately prints "got a", the program exits (I see the command
prompt), then it prints "got b".
I have tried executing with "LD_ASSUME_KERNEL=2.2.5" which uses
/lib/libc.so.6 (I believe that's the linuxthreads version of
glibc-2.3.4) and with "LD_ASSUME_KERNEL=2.6.9" which uses
/lib/tls/i686/libc.so.6 (I believe that is the NPTL version of
glibc-2.3.4). Both libraries behave identically.
I also have an embedded mips system running
linux-2.6.18/glibc-2.3.6/linuxthreads, but it behaves exactly as I
expect (waits 1 sec, prints "got b", then prints "got a", then exits).
Are my expectations wrong, or am I triggering a bug in linux-2.6.9 or
in glibc-2.3.4?
Thanks,
Dave
More information about the Libc-help
mailing list