1999-01-15 21:35:35 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <error.h>
|
|
|
|
#include <errno.h>
|
1999-01-18 17:38:36 +08:00
|
|
|
#include <sys/wait.h>
|
1999-01-15 21:35:35 +08:00
|
|
|
|
|
|
|
void noop (void);
|
|
|
|
|
1999-01-19 23:41:14 +08:00
|
|
|
#define NR 2 /* Exit code of the child. */
|
|
|
|
|
1999-01-15 21:35:35 +08:00
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
1999-01-19 23:41:14 +08:00
|
|
|
pid_t pid;
|
|
|
|
int status;
|
1999-01-15 21:35:35 +08:00
|
|
|
|
|
|
|
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 ();
|
1999-01-19 23:41:14 +08:00
|
|
|
_exit (NR);
|
1999-01-15 21:35:35 +08:00
|
|
|
}
|
|
|
|
else if (pid < 0)
|
|
|
|
error (1, errno, "vfork");
|
|
|
|
printf ("After vfork (parent)\n");
|
1999-01-19 23:41:14 +08:00
|
|
|
if (waitpid (0, &status, 0) != pid
|
1999-02-15 04:03:55 +08:00
|
|
|
|| !WIFEXITED (status) || WEXITSTATUS (status) != NR)
|
1999-01-19 23:41:14 +08:00
|
|
|
exit (1);
|
1999-01-15 21:35:35 +08:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
noop ()
|
|
|
|
{
|
|
|
|
}
|