This is the mail archive of the
libc-hacker@cygnus.com
mailing list for the glibc project.
A test for vfork
- To: libc-hacker@cygnus.com
- Subject: A test for vfork
- From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
- Date: 15 Jan 1999 11:13:36 +0100
Here is a test for vfork which should tell you if it is implemented
correctly. Especially the generic source linux/vfork.c is unusable for
machines that put the return pc on the stack (like ix86). Remember that
the stack is shared between the parent and the child, thus any function
call in the child will clobber the return pc from vfork of the parent.
See the existing implementations under sysdeps/unix for hints.
Andreas.
----------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
void noop (void);
int
main (void)
{
int pid;
printf ("Before vfork\n");
fflush (stdout);
pid = vfork ();
if (pid == 0)
{
/* This will clobber the return pc from vfork in the parent on
machines where it is stored on the stack, if vfork wasn't
implemented correctly, */
noop ();
_exit (2);
}
else if (pid < 0)
error (1, errno, "vfork");
printf ("After vfork (parent)\n");
wait (0);
exit (0);
}
void noop () {}
----------------------------------------------------------------------