Browse Source

Implement basic feature

develop
Damien Goutte-Gattat 8 years ago
parent
commit
0bd65c782f
  1. 29
      src/wait4.c

29
src/wait4.c

@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <err.h>
/* Help and informations about the program. */
@ -58,12 +60,29 @@ See the COPYING file or <http://www.gnu.org/licenses/gpl.html>.\n\
}
/* Helper functions. */
static int
get_integer_or_die(const char *arg)
{
int val;
char *endptr;
errno = 0;
val = strtol(arg, &endptr, 10);
if ( errno != 0 || endptr == arg )
errx(EXIT_FAILURE, "invalid argument, integer expected: %s");
return val;
}
/* Main function. */
int
main(int argc, char **argv)
{
int c;
int c, pid;
struct option options[] = {
{ "help", 0, NULL, 'h' },
@ -89,5 +108,13 @@ main(int argc, char **argv)
}
}
if ( argc - optind != 1 )
usage(EXIT_FAILURE);
pid = get_integer_or_die(argv[optind]);
if ( wait4pid(pid) == -1 )
err(EXIT_FAILURE, "cannot wait for process %d", pid);
return EXIT_SUCCESS;
}
Loading…
Cancel
Save