Skip to content

Commit

Permalink
Resolve issue smuos#4: Create fork()
Browse files Browse the repository at this point in the history
  • Loading branch information
JINGJINGTANG committed Sep 27, 2014
1 parent 252a4bc commit 721c58c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Binary file modified mm
Binary file not shown.
16 changes: 16 additions & 0 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 @@ -50,6 +51,21 @@ int main(int argc, char *argv[]) {
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}
// Fork the process
int rc = fork();

// Fork failed
if (rc < 0) {
fprintf(stderr, "Fork failed!\n");
exit(1);
// The child process
} else if (rc == 0) {
median(length, pt);
// The parent process
} else {
mean(length, pt);
}

fprintf(stdout, "\nThe mean is: %f", mean(length, pt));
fprintf(stdout, "\nThe median is: %f", median(length, pt));
fprintf(stdout, "\n%s: FIN. \n", argv[0]);
Expand Down

0 comments on commit 721c58c

Please sign in to comment.