Skip to content

Commit

Permalink
Change output#2
Browse files Browse the repository at this point in the history
  • Loading branch information
zekewang918 committed Sep 27, 2014
1 parent 981a776 commit c8668c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Binary file modified mm
Binary file not shown.
11 changes: 6 additions & 5 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ int main(int argc, char *argv[]) {
// Sort numbers
qsort(pt, length, sizeof(int), numcmp);

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

// Initilaztion fork() for process
int rc = fork();
Expand All @@ -93,7 +90,11 @@ int main(int argc, char *argv[]) {
exit(FAILURE);
// If the process is child
} else if (rc == 0){
// Print child'spid and median
//print out sorted number
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}
// Print child's pid and median
fprintf(stdout, "\n%s: This is child process(pid:%d)\n", argv[0], (int)getpid());
fprintf(stdout, "%s: The median is: %f\n", argv[0], median(pt, length));
// If the process is parent
Expand Down
15 changes: 8 additions & 7 deletions mm.c~
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ int main(int argc, char *argv[]) {
// Sort numbers
qsort(pt, length, sizeof(int), numcmp);

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

// Initilaztion fork() for process
int rc = fork();
Expand All @@ -93,8 +90,12 @@ int main(int argc, char *argv[]) {
exit(FAILURE);
// If the process is child
} else if (rc == 0){
// Print child'spid and median
fprintf(stdout, "\n%s: This is child process(pid:%d)\n", argv[0], (int)getpid());
//print out sorted number
for (i=0; i<length; i++) {
fprintf(stdout, "%d ", pt[i]);
}
// Print child's pid and median
fprintf(stdout, "%s: This is child process(pid:%d)\n", argv[0], (int)getpid());
fprintf(stdout, "%s: The median is: %f\n", argv[0], median(pt, length));
// If the process is parent
} else if (rc > 0){
Expand Down

0 comments on commit c8668c6

Please sign in to comment.