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