summaryrefslogtreecommitdiff
path: root/src/libstddjb/wait_pids_nohang.c
blob: c13ddec3a99f0090fb439fe1ab6411cb66639a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* ISC license. */

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

int wait_pids_nohang (pid_t const *pids, unsigned int len, int *wstat)
{
  for (;;)
  {
    int w ;
    pid_t r = wait_nohang(&w) ;
    if (!r || (r == (pid_t)-1)) return (int)r ;
    {
      unsigned int i = 0 ;
      for (; i < len ; i++) if (r == pids[i]) break ;
      if (i < len)
      {
        *wstat = w ;
        return 1+i ;
      }
    }
  }
}