waitpid.c 868 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #ifdef __MINGW32__
  19. #include <process.h>
  20. #define wait(s) _cwait(s,pid,_WAIT_CHILD)
  21. #endif
  22. pid_t
  23. waitpid (pid_t pid, int *stat_loc, int options ATTRIBUTE_UNUSED)
  24. {
  25. for (;;)
  26. {
  27. int wpid = wait(stat_loc);
  28. if (wpid == pid || wpid == -1)
  29. return wpid;
  30. }
  31. }