summaryrefslogtreecommitdiff
path: root/src/libstddjb/waitn_reap.c
blob: 96a0c6179c9abb4b44c780a34177f8962c1794fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ISC license. */

#include <sys/types.h>
#include <skalibs/djbunix.h>

int waitn_reap (pid_t *pids, unsigned int len)
{
  unsigned int n = 0 ;
  while (len)
  {
    int w ;
    register int r = wait_pids_nohang(pids, len, &w) ;
    if (r < 0) return r ;
    else if (!r) break ;
    pids[r-1] = pids[--len] ;
    n++ ;
  }
  return (int)n ;
}