fork.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * fork test for uClibc
  4. *
  5. * Copyright (C) 1999,2000 by Lineo, inc.
  6. * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <unistd.h>
  26. #include <sys/wait.h>
  27. int main(void)
  28. {
  29. pid_t pid;
  30. int status, wpid;
  31. if ((pid = fork()) == 0) {
  32. printf("The child process sleeps 5 seconds...\n");
  33. sleep(5);
  34. printf("Child exiting.\n");
  35. exit(-1);
  36. }
  37. printf("Parent: waiting for the child to die.\n");
  38. while (1) {
  39. wpid = wait(&status);
  40. if (wpid > 0 && wpid != pid) {
  41. continue;
  42. }
  43. if (wpid == pid)
  44. break;
  45. }
  46. printf("Child process exited.\nGoodbye.\n");
  47. return EXIT_SUCCESS;
  48. }
  49. /*
  50. Local Variables:
  51. c-file-style: "linux"
  52. c-basic-offset: 4
  53. tab-width: 4
  54. End:
  55. */