Browse Source

Accept arbitrary number of pids

develop
Damien Goutte-Gattat 8 years ago
parent
commit
d7d3736513
  1. 12
      src/wait4.c

12
src/wait4.c

@ -82,7 +82,7 @@ get_integer_or_die(const char *arg)
int
main(int argc, char **argv)
{
int c, pid, ec;
int c, ec, len, *pids, i;
struct option options[] = {
{ "help", 0, NULL, 'h' },
@ -108,13 +108,15 @@ main(int argc, char **argv)
}
}
if ( argc - optind != 1 )
if ( (len = argc - optind) < 1 )
usage(EXIT_FAILURE);
pid = get_integer_or_die(argv[optind]);
pids = malloc(len * sizeof(int));
for ( i = 0; i < len; i++ )
pids[i] = get_integer_or_die(argv[optind + i]);
if ( (ec = wait4pid(pid)) == -1 )
err(EXIT_FAILURE, "cannot wait for process %d", pid);
if ( (ec = wait4all(pids, len)) == -1 )
err(EXIT_FAILURE, "cannot wait for processes");
return ec;
}
Loading…
Cancel
Save