vfork.c 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * vfork test for uClibc
  4. * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <sys/wait.h>
  12. #include <sys/types.h>
  13. int main(void)
  14. {
  15. pid_t pid;
  16. int status, wpid;
  17. char *argv[] = {
  18. "/bin/ls",
  19. "-laF",
  20. NULL,
  21. };
  22. clearenv();
  23. if ((pid = vfork()) == 0) {
  24. printf("Hi. I'm the child process...\n");
  25. execvp(argv[0], argv);
  26. _exit(0);
  27. }
  28. printf("Hello. I'm the parent process.\n");
  29. while (1) {
  30. wpid = wait(&status);
  31. if (wpid > 0 && wpid != pid) {
  32. continue;
  33. }
  34. if (wpid == pid)
  35. break;
  36. }
  37. printf("Child process exited.\nGoodbye.\n");
  38. return EXIT_SUCCESS;
  39. }
  40. /*
  41. Local Variables:
  42. c-file-style: "linux"
  43. c-basic-offset: 4
  44. tab-width: 4
  45. End:
  46. */