Skip to content

Commit

Permalink
Make mm.c fork(), with parent calling mean() and child median()
Browse files Browse the repository at this point in the history
Resolve smuos#4
  • Loading branch information
DylanYoung committed Sep 24, 2014
1 parent 7cfcf60 commit 49ae891
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,24 @@ int main(int argc, char *argv[]) {

// Sort numbers
qsort(pt, length, sizeof(int), numcmp);

// Calculate the mean
double m = mean(pt, length, sizeof(int));

int rc = fork(NULL);
double m;
if (rc < 0)
exit(-1);
else if (rc == 0){
// Calculate the median
m = median(pt, length);
}
else{
wait(NULL);
// Calculate the mean
m = mean(pt, length, sizeof(int));
}

// Calculate the median
double mm = median(pt, length);

// Print the mean:
fprintf(stdout, "%s: The mean is %f \n", argv[0], m);

// Print the median:
fprintf(stdout, "%s: The median is %f \n", argv[0], mm);
// Print the mean?:
fprintf(stdout, "%s: The mean? is %f \n", argv[0], m);

// Print out sorted numbers
fprintf(stdout, "%s: Sorted output is: \n", argv[0]);
Expand Down

0 comments on commit 49ae891

Please sign in to comment.