From e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad Mon Sep 17 00:00:00 2001 From: klaar36 Date: Fri, 20 Mar 2015 17:30:24 +0100 Subject: Initial Pintos --- src/examples/generic_parent.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/examples/generic_parent.c (limited to 'src/examples/generic_parent.c') diff --git a/src/examples/generic_parent.c b/src/examples/generic_parent.c new file mode 100644 index 0000000..dd8f11d --- /dev/null +++ b/src/examples/generic_parent.c @@ -0,0 +1,48 @@ +/* klaar@ida + + Will try to start N child-processes, giving each an increasing + number starting on S as argument to main. Will return S+C where C + is the number of sucessfully started children. + + Normally used from some parent program. + */ + +#include +#include +#include + +#define BUF_SIZE 64 + +int main(int argc, char* argv[]) +{ + int i; + char cmd[BUF_SIZE]; + char* child; + int start; + int count; + + if (argc != 4) + { + printf("Usage: %s CHILD S N\n", argv[0]); + printf("%s starts N copies of CHILD.\n", argv[0]); + printf("Each child receives an unique integer I as first parameter in the range S..(S+N-1).\n"); + printf("Returns S + N on success, S + I if only I children could be started.\n"); + return -1; + } + + child = argv[1]; + start = atoi(argv[2]); + count = atoi(argv[3]); + + for(i = 0; i < count; i++) + { + snprintf(cmd, BUF_SIZE, "%s %i", child, start + i); + if (exec(cmd) == -1) + { + printf("!! ERROR !!\n"); + printf("Could not start '%s'\n", cmd); + break; + } + } + exit(start + i); +} -- cgit v1.2.1