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

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

int waitn (pid_t *pids, unsigned int n)
{
  while (n)
  {
    int wstat ;
    register unsigned int i = 0 ;
    register pid_t pid = wait_nointr(&wstat) ;
    if (pid < 0) return 0 ;
    for (; i < n ; i++) if (pid == pids[i]) break ;
    if (i < n) pids[i] = pids[--n] ;
  }
  return 1 ;
}