From 9514a375c172c1ebf3e35af428cfc28e4efc7914 Mon Sep 17 00:00:00 2001 From: Yumingz Date: Tue, 30 Sep 2014 00:51:10 +0000 Subject: [PATCH] fixed #4, make mm.c fork(), have the parent call mean() and child call median() --- mm.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mm.c b/mm.c index b9297fb..ccebbd5 100644 --- a/mm.c +++ b/mm.c @@ -1,5 +1,6 @@ #include #include +#include #define debug 0 @@ -51,7 +52,7 @@ int main(int argc, char *argv[]) { int i, length, *pt; - // Check for proper usage + // Check for prioper usage if (argc < 2) { fprintf(stderr, "%s: Aborting, not enough arguments.\n", argv[0]); return (-1); @@ -83,6 +84,21 @@ int main(int argc, char *argv[]) { fprintf(stdout, "%d ", pt[i]); } fprintf(stdout, "\n%s: FIN. \n", argv[0]); - return 0; + // Add fork + int rc = fork(); + // Fork problem + if (rc < -1) { + fprintf(stdout,"Can't fork!\n"); + exit(0); + } + else if (rc == 1) { + printf("Hello, I am child, I should print the median"); + int child = median(pt, length); + } + else if (rc == 2) { + printf("Hello, I am parent, I should print the mean"); + int parent = mean(pt, length); + } + }