diff options
| author | Felipe Boeira <felipe.boeira@liu.se> | 2019-01-08 18:39:03 +0100 |
|---|---|---|
| committer | Felipe Boeira <felipe.boeira@liu.se> | 2019-01-08 18:39:03 +0100 |
| commit | d4522b8e9854178473adcea0fbb84f23f6e744bd (patch) | |
| tree | fbcf620617c5023154eba3f965b3a982daa64a47 /src/examples/parent.c | |
| download | pintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz | |
Initial commit
Diffstat (limited to 'src/examples/parent.c')
| -rw-r--r-- | src/examples/parent.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/examples/parent.c b/src/examples/parent.c new file mode 100644 index 0000000..7555b2b --- /dev/null +++ b/src/examples/parent.c @@ -0,0 +1,41 @@ +/* parent.c + * A test program that calls itself recursively. + * In the last step of the recursion child.c is started. + * Do not use with large CHILDREN or DEPTH. + */ +#include <syscall.h> +#include <stdlib.h> +#include <stdio.h> + +#define CHILDREN 4 +#define DEPTH 3 + +int main(int argc, char* argv[]) +{ + int i; + int pid[CHILDREN]; + int depth = DEPTH - 1; + char cmd[10]; + + if (argc == 2) + depth = atoi(argv[1]) - 1; + + for(i = 0; i < CHILDREN; i++) + { + if (depth) + snprintf(cmd, 10, "parent %i", depth); + else + snprintf(cmd, 10, "child %i", i); + + printf("%s\n", cmd); + pid[i] = exec(cmd); + } +// if (depth <= 1) + { + for(i = 0; i < CHILDREN; i++) + { + wait(pid[i]); + } + } + exit(0); +} |
