Skip to content

Commit

Permalink
Close smuos#4 Close smuos#5 Close smuos#6
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozenfire92 committed Sep 23, 2014
1 parent 75bf591 commit df867d5
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions mm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#define debug 0

Expand Down Expand Up @@ -60,18 +61,25 @@ int main(int argc, char *argv[]) {
qsort(pt, length, sizeof(int), numcmp);

// Print out numbers
fprintf(stdout, "%s: Sorted output is: \n", argv[0]);
fprintf(stdout, "%s:(%d) Sorted output is: \n", argv[0], getpid());
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}
printf("\n"); // This is required otherwise it runs the for loop twice?

// Print Mean
float calculatedMean = mean(pt, length);
fprintf(stdout, "\n%s: Mean is: %.3f", argv[0], calculatedMean);

// Print Median
float calculatedMedian = median(pt, length);
fprintf(stdout, "\n%s: Median is: %.3f", argv[0], calculatedMedian);
// Fork the process
int returnCode = fork();
if (returnCode < 0) {
fprintf(stderr, "%s: DEBUG: fork failed: returnCode: %d.\n", argv[0], returnCode);
} else if (returnCode == 0) {
// Child Print Median
float calculatedMedian = median(pt, length);
fprintf(stdout, "\n%s:(%d C) Median is: %.3f", argv[0], getpid(), calculatedMedian);
} else if (returnCode > 0) {
// Parent Print Mean
float calculatedMean = mean(pt, length);
fprintf(stdout, "\n%s:(%d P) Mean is: %.3f", argv[0], getpid(), calculatedMean);
}

fprintf(stdout, "\n%s: FIN. \n", argv[0]);

Expand Down

0 comments on commit df867d5

Please sign in to comment.