aboutsummaryrefslogtreecommitdiffstats
path: root/P1
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--P1/src/mapreduce.c15
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;
}
}