vfork.c 910 B

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