Browse Source

Add wait4all function (/proc mode)

develop
Damien Goutte-Gattat 8 years ago
parent
commit
5b520700ec
  1. 34
      src/wait4pid.c

34
src/wait4pid.c

@ -192,4 +192,38 @@ wait4pid(pid_t pid)
return errno == ENOENT ? 0 : -1;
}
int
wait4all(pid_t *pids, size_t len)
{
int nproc, i;
char *paths;
struct stat st_buf;
paths = malloc(20 * len);
for ( i = 0; i < len; i++ )
snprintf(paths + 20 * i, 20, "/proc/%d", pids[i]);
nproc = len;
while ( nproc > 0 ) {
for ( i = 0; i < len; i++ ) {
if ( pids[i] == -1 )
continue;
if ( stat(paths + 20 * i, &st_buf) == -1 ) {
if ( errno != ENOENT )
return -1;
pids[i] = -1;
nproc -= 1;
}
}
sleep(1);
}
free(paths);
return 0;
}
#endif /* ! HAVE_LINUX_NETLINK_H */
Loading…
Cancel
Save