Skip to content

Commit

Permalink
fixes smuos#6 Make the parent wait til child.
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyymmoT committed Sep 25, 2014
1 parent ebb32dc commit 515d4f0
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ int main(int argc, char *argv[]) {
for (i = 0; i < length; i++) {
pt[i] = (int) strtol(argv[i+1], NULL, 10);
}

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

// Print out numbers
fprintf(stdout, "%s: Sorted output is: \n", argv[0]);
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}
fprintf(stdout, "\n%s: FIN. \n", argv[0]);

//fork()
int rc = fork();
Expand All @@ -92,18 +90,16 @@ int main(int argc, char *argv[]) {
else if(rc == 0)
{
//child
fprintf(stdout, "\n%d ", median(pt, length));
fprintf(stdout, "\nThis is the median: %d ", median(pt, length));
}

else if (rc > 0)
{
//parent
int waitCode = wait(NULL);
fprintf(stdout, "\n%d ", mean(pt, length));
fprintf(stdout, "\nThis is the mean: %d \n", mean(pt, length));
fprintf(stdout, "\n%s: FIN. \n", argv[0]);
}




return 0;
}

0 comments on commit 515d4f0

Please sign in to comment.