diff options
author | Matt Strapp <strap012@umn.edu> | 2020-10-06 19:32:32 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-10-06 19:32:32 -0500 |
commit | e2a806a832ce40976b1a52f19ebc48366dd3f05a (patch) | |
tree | 21b60d512e81691c55e9f5fef7bb339947c9df6c /P1 | |
parent | Add another define (diff) | |
download | csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.tar csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.tar.gz csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.tar.bz2 csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.tar.lz csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.tar.xz csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.tar.zst csci4061-e2a806a832ce40976b1a52f19ebc48366dd3f05a.zip |
Add more error handling
Diffstat (limited to 'P1')
-rw-r--r-- | P1/src/mapreduce.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/P1/src/mapreduce.c b/P1/src/mapreduce.c index cb171bb..8243e17 100644 --- a/P1/src/mapreduce.c +++ b/P1/src/mapreduce.c @@ -26,6 +26,9 @@ int main(int argc, char *argv[]) { //send chunks of data to the mappers in RR fashion sendChunkData(inputFile, nMappers); exit(0); + } else if (pid == -1) { + printf("Fork failed!\n"); + return 1; } sleep(1); @@ -38,13 +41,13 @@ int main(int argc, char *argv[]) { sprintf(numMap, "%d", i); execl("./mapper", "./mapper", &numMap, NULL); printf("Mapper execution failed! Make sure \"mapper\" exists in the directory.\n"); - return 4; + return 2; } else if (mapperPid == -1) { printf("Fork failed!\n"); return 1; } } - + for (int i = 0; i <= nMappers; i++) { int waitError = wait(NULL); if (waitError == -1) @@ -53,7 +56,6 @@ int main(int argc, char *argv[]) { return 5; } } - // ###### DO NOT REMOVE ###### // shuffle sends the word.txt files generated by mapper // to reducer based on a hash function @@ -61,6 +63,9 @@ int main(int argc, char *argv[]) { if(pid == 0){ shuffle(nMappers, nReducers); exit(0); + } else if (pid == -1) { + printf("Fork failed!\n"); + return 1; } sleep(1); @@ -73,10 +78,10 @@ int main(int argc, char *argv[]) { sprintf(numRed, "%d", i); execl("./reducer", "./reducer", &numRed, NULL); printf("Reducer execution failed! Make sure \"reducer\" exists in the directory.\n"); - return 3; + return 2; } else if (reducerPid == -1) { printf("Fork failed!\n"); - return 2; + return 1; } } |