source: vendor/glibc-tests/glibc/posix/test-vfork.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 769 bytes
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <error.h>
5#include <errno.h>
6#include <sys/wait.h>
7
8void __attribute_noinline__ noop (void);
9
10#define NR 2 /* Exit code of the child. */
11
12int
13main (void)
14{
15 pid_t pid;
16 int status;
17
18 printf ("Before vfork\n");
19 fflush (stdout);
20 pid = vfork ();
21 if (pid == 0)
22 {
23 /* This will clobber the return pc from vfork in the parent on
24 machines where it is stored on the stack, if vfork wasn't
25 implemented correctly, */
26 noop ();
27 _exit (NR);
28 }
29 else if (pid < 0)
30 error (1, errno, "vfork");
31 printf ("After vfork (parent)\n");
32 if (waitpid (0, &status, 0) != pid
33 || !WIFEXITED (status) || WEXITSTATUS (status) != NR)
34 exit (1);
35
36 return 0;
37}
38
39void
40noop ()
41{
42}
Note: See TracBrowser for help on using the repository browser.