Browse Source

Add basic support for kevent

develop
Damien Goutte-Gattat 8 years ago
parent
commit
2c77c61c17
  1. 32
      src/wait4pid.c

32
src/wait4pid.c

@ -170,10 +170,40 @@ wait4all(pid_t *pids, size_t len)
#elif defined HAVE_SYS_EVENT_H /* BSD Kevent */
#include <sys/event.h>
#include <xmem.h>
int
wait4all(pid_t *pids, size_t len)
{
return 0;
int fd, i, nproc, ec;
struct kevent *evts, evt;
if ( (fd = kqueue()) == -1 )
return -1;
evts = xmalloc(sizeof(struct kevent) * len);
for ( i = 0; i < len; i++ ) {
EV_SET(evts[i], pids[i], EVFILT_PROC, EV_ENABLE, NOTE_EXIT, 0, 0):
}
i = kevent(fd, evts, len, NULL, 0, 0);
free(evts);
if ( i == -1 )
return -1;
nproc = len;
ec = 0;
while ( nproc > 0 ) {
if ( kevent(fd, NULL, 0, &evt, 1, 0) <= 0 )
return -1;
if ( evt->ident == pids[len - 1] )
ec = evt->data;
nproc -= 1;
}
return ec;
}
#else /* Fallback */

Loading…
Cancel
Save