diff options
| author | klaar36 <klas.arvidsson@liu.se> | 2015-03-20 17:30:24 +0100 |
|---|---|---|
| committer | klaar36 <klas.arvidsson@liu.se> | 2015-03-20 17:30:24 +0100 |
| commit | e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch) | |
| tree | 4de97af7207676b69cb6a9aba8cb443cc134855d /src/examples/parent.c | |
| parent | b0418a24e709f0632d2ede5b0f327c422931939b (diff) | |
| download | pintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz | |
Initial Pintos
Diffstat (limited to 'src/examples/parent.c')
| -rw-r--r-- | src/examples/parent.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/examples/parent.c b/src/examples/parent.c new file mode 100644 index 0000000..df0e8f7 --- /dev/null +++ b/src/examples/parent.c @@ -0,0 +1,52 @@ +/* klaar@ida + + pintos -v -k --fs-disk=2 --qemu -p ../examples/parent -a parent -p ../examples/child -a child -- -f -q run parent | grep PASS > result.txt + grep -c 'Lab 0' result.txt + grep -c 'Lab 1' result.txt + grep -c 'Lab 2' result.txt + grep -c 'Lab 3' result.txt + + A test program that calls itself recursively. In the last step of + the recursion child.c is started. Do not use with large values for + CHILDREN or DEPTH. + + Shall produce 64 PASS messages, 16 of each, when CHILDREN=4 and DEPTH=3 + + CHILDREN^DEPTH=count(PASS) (4^3=64) +*/ +#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); +} |
