diff options
author | Andrea Smith <smit9523@umn.edu> | 2020-10-05 23:02:07 -0500 |
---|---|---|
committer | Andrea Smith <smit9523@umn.edu> | 2020-10-05 23:02:07 -0500 |
commit | c960e6f395610a72aef5f21e49103b1d1633a7ec (patch) | |
tree | d42ccc202506a6293cf6835eb160601efe7cfd3b /P1/src | |
parent | Updated README (diff) | |
parent | Add error handling (Fixing #4 again) (diff) | |
download | csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.tar csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.tar.gz csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.tar.bz2 csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.tar.lz csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.tar.xz csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.tar.zst csci4061-c960e6f395610a72aef5f21e49103b1d1633a7ec.zip |
Merge branch 'master' of github.umn.edu:STRAP012/csci4061Projects
Diffstat (limited to '')
-rw-r--r-- | P1/src/mapreduce.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/P1/src/mapreduce.c b/P1/src/mapreduce.c index 9efccf7..19cf937 100644 --- a/P1/src/mapreduce.c +++ b/P1/src/mapreduce.c @@ -11,6 +11,10 @@ int main(int argc, char *argv[]) { // ###### DO NOT REMOVE ###### int nMappers = strtol(argv[1], NULL, 10); int nReducers = strtol(argv[2], NULL, 10); + if (nMappers < nReducers) { + printf("Number of mappers must be greater than or equal to the number of reducers.\n"); + exit(2); + } char *inputFile = argv[3]; // ###### DO NOT REMOVE ###### @@ -34,14 +38,24 @@ int main(int argc, char *argv[]) { char numMap[10]; sprintf(numMap, "%d", i); execl("./mapper", "./mapper", &numMap, NULL); + printf("Mapper execution failed! Make sure \"mapper\" exists in the directory.\n"); + return 4; + } else if (mapperPid == -1) { + printf("Fork failed!\n"); + return 1; } } for (int i = 0; i <= nMappers; i++) { //Hopefully this works - wait(NULL); + int waitError = wait(NULL); + if (waitError == -1) + { + printf("Wait failed!\n"); + return 5; + } } - +printf("Not stuck here.\n"); // ###### DO NOT REMOVE ###### // shuffle sends the word.txt files generated by mapper @@ -53,7 +67,7 @@ int main(int argc, char *argv[]) { } sleep(1); - +printf("Not stuck here.\n"); pid_t reducerPid; for (int i = 1; i <= nReducers; i++) { @@ -62,12 +76,21 @@ int main(int argc, char *argv[]) { char numRed[10]; sprintf(numRed, "%d", i); execl("./reducer", "./reducer", &numRed, NULL); + printf("Reducer execution failed! Make sure \"reducer\" exists in the directory.\n"); + return 3; + } else if (reducerPid == -1) { + printf("Fork failed!\n"); + return 2; } } for (int i = 0; i <= nReducers; i++) { //Maybe this works too? - wait(NULL); + int waitError = wait(NULL); + if (waitError == -1) { + printf("Wait failed!\n"); + return 5; + } } return 0; |