skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

waitn_reap_posix.c (436B)


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