waitpid.c 777 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. @deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
  3. This is a wrapper around the @code{wait} function. Any ``special''
  4. values of @var{pid} depend on your implementation of @code{wait}, as
  5. does the return value. The third argument is unused in @libib{}.
  6. @end deftypefn
  7. */
  8. #ifdef HAVE_CONFIG_H
  9. #include "config.h"
  10. #endif
  11. #include "ansidecl.h"
  12. /* On some systems (such as WindISS), you must include <sys/types.h>
  13. to get the definition of "pid_t" before you include <sys/wait.h>. */
  14. #include <sys/types.h>
  15. #ifdef HAVE_SYS_WAIT_H
  16. #include <sys/wait.h>
  17. #endif
  18. pid_t
  19. waitpid (pid_t pid, int *stat_loc, int options ATTRIBUTE_UNUSED)
  20. {
  21. for (;;)
  22. {
  23. int wpid = wait(stat_loc);
  24. if (wpid == pid || wpid == -1)
  25. return wpid;
  26. }
  27. }