1999-01-15 21:35:35 +08:00
|
|
|
#include <stdio.h>
|
2000-06-21 20:39:22 +08:00
|
|
|
#include <stdlib.h>
|
1999-01-15 21:35:35 +08:00
|
|
|
#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
|
|
|
|
2003-01-10 03:45:08 +08:00
|
|
|
void __attribute_noinline__ noop (void);
|
1999-01-15 21:35:35 +08:00
|
|
|
|
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);
|
2000-12-31 18:52:32 +08:00
|
|
|
|
|
|
|
return 0;
|
1999-01-15 21:35:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-08 08:22:23 +08:00
|
|
|
noop (void)
|
1999-01-15 21:35:35 +08:00
|
|
|
{
|
|
|
|
}
|