waitn_posix.c (433B)
1 /* ISC license. */ 2 3 #include <sys/wait.h> 4 5 #include <skalibs/djbunix.h> 6 7 int waitn_posix (pid_t *pids, unsigned int n, int *w) 8 { 9 pid_t wanted = n ? pids[n-1] : 0 ; 10 while (n) 11 { 12 int wstat ; 13 unsigned int i = 0 ; 14 pid_t pid = wait_nointr(&wstat) ; 15 if (pid < 0) return 0 ; 16 for (; i < n ; i++) if (pid == pids[i]) break ; 17 if (i < n) pids[i] = pids[--n] ; 18 if (pid == wanted) *w = wstat ; 19 } 20 return 1 ; 21 }