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