From f3156831364fb2d3bec8c2f7ba7e8c10e91be13e Mon Sep 17 00:00:00 2001 From: Felipe Boeira Date: Wed, 4 Mar 2020 14:56:13 +0100 Subject: Added missing files --- src/examples/recursor_ng.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/examples/recursor_ng.c (limited to 'src/examples') diff --git a/src/examples/recursor_ng.c b/src/examples/recursor_ng.c new file mode 100644 index 0000000..fcf6b3c --- /dev/null +++ b/src/examples/recursor_ng.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#define MAX_SPAWN 100 + +int main (int argc, char *argv[]) +{ + char buffer[128]; + pid_t pid[MAX_SPAWN]; + int retval = 0; + int i, spawn; + int ret = 0; + + if (argc != 4) + { + printf ("usage: recursor_ng \n"); + exit (1); + } + + /* Print args. */ + //printf ("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]); + printf("+"); + /* Execute child and wait for it to finish if requested. */ + spawn = atoi (argv[2]); + + if (spawn > MAX_SPAWN) { + printf("Greater than MAX_SPAWN\n"); + exit(-1); + } + + if (spawn != 0) + { + for (i = 0; i < spawn;i++) { + snprintf (buffer, sizeof buffer, + "recursor_ng %s %d %s", argv[1], atoi (argv[2]) - 1, argv[3]); + pid[i] = exec (buffer); + } + if (atoi (argv[3])) { + for (i = 0; i < spawn;i++) { + retval = wait (pid[i]); + if (retval < 0) + ret = 1; + } + } + + /* Done. */ + if (ret) + printf("YOU HAVE FAILED\n"); + } + exit (ret); +} -- cgit v1.2.1