From e479d5f7396a50af2b8234c960c869a492f183a1 Mon Sep 17 00:00:00 2001 From: Xike Wang Date: Fri, 26 Sep 2014 21:27:53 -0300 Subject: [PATCH] Fix #3: Make mm.c fork(), parent call mean() and child call median() --- mm | Bin 8848 -> 8976 bytes mm.c | 31 ++++++++++++++++++++++++++----- mm.c~ | 40 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/mm b/mm index 7f02c880b4540474dbc460c01207346b2828f5ed..5fb1da54a51fc67184396bc3bbb590be6b73686f 100755 GIT binary patch delta 1576 zcmZ8heP|nH7=Q0_hfUJ-l6H!-&RrsztU`j*J`cCNe}S3>G#SfflTa8mF-R;UBYpFh-T5h+eedWPd0!iO>7qwUZq8KF{-e z-uL%=-jBOi$NHFlwbO7S#36(t0vLD<=gHMU-)M)Geb7pxQSvA^>u$6O>ve+$#0e7C<(?zO6kGFC2 z!|}-Cz|6&5{Q5mHgdTp%OXyW_mA;A*a)+(|WhO78HGU(~!cktvj&r_w};9P)loC;~;DMtKX*^i+6GG3$VD!!`W zwVl|MDt%U&v_(2(lcIP{(VjK5O=XzxQ6Q@LYhZ{FLAciV4CZdW#PTcU;tJK2N|o)F z);3G4y>$Xl!uZcEg)62E!8&tph7vV#l@Y^=TCAI$&<~4YYto8!^%6|vZ#FFS2^%)3 zXs;UDJ`+YSDe7P94box}p`AYMfaIqKa#cx52L$J@F<}6K6My zR?YWlsuDU!Yiq?SD{2i3J=0oro)uN`yXGVuC9q2R?V|Hgbleg<&cp`V7=H+M6}|$W zir<0t(7#2+ryAf8Gw@Z=Si`rJH@?aq{8DcQuK~Royw2FV`zd|GWH#C-M^Z<>n&?rPBdZ3A?X|zbA-84E+d{V45mdU*$ zk42KHcuWrFU1&0q%**gb6UkIe&gL@Fcs}2gO~(3zv0mC8m(%fBGBOK;`sLvC1|b{C z#b*n^po9&EO}IVW6$IMYu8AG8i(U%kjC7BOUOG>}lxQ0zUr75yN9?QRE!*q1KV$o| zw!dimCF&POycZ2bd>Ay4Ii3@Rnqto8fSCK*}^o1VSqF70<4ar zVL<6fDwT;+qyRdc&*YfKZUFg0u8>JV7a}G3VczH>7v;@e^-aiuYIlM$?tcLUv&TBd7?|&Yc}eyl{TLbI*6qxtDvD%Zi|^ zB=Qyj1^}iFsBrO?$&E4+V9c>8(Eu!wJjQKXPl)Cf>CtsE#<&xcxM*}-k0x0wb1PZ2xowyAn_udqt`*yoIqWEiTML!`%0!0=?+kj9wFqM?LUSn|hEY^VK3d4LAA zED9y_c7S-aRtN5pdSfONL&i*LCY8n~Ymbl_W0v*B>-?RKj|KNriOG{j%Qb5e^EBM@uoz%NR)*w zQMS%PNM!(m!uBpMNmvgD8S>JS>RQ04C<&@qN-J~sa8?j~g~`z(o0{2IWCGJAVU6rq zTx=6VT=5r1QfLKV;bUrKQ{6$vH!K(wBDA_Be36Ani4fv^u4tQ)C@E7XwF(hYu2SWs zF`Rc^W2_*Kx3E?(Pp9!0Bk(qMQKkJX8< z4#Mly%b?yW^-fW5nY>MCv&B`ld%VTGvjfm;>+*QX11{$<{TAmiiOLfBz+IngF=s^d zKk!qxpg-t1YVo-|;fP{7X|y@`I%4E2@;h$#cX+ym>=YmQDj2;66Y*FP;#mNBt$%M5x z=lk(H(0fQn;m{e?f3-u$TRNuaru)2wJhZ#=Y7ru$Ol{pjy&tz6z?~%9ae_2B(#fc! OB1S(R`RX`hr1XEkW+Qq4 diff --git a/mm.c b/mm.c index 8d60c00..9306ab1 100644 --- a/mm.c +++ b/mm.c @@ -1,7 +1,14 @@ #include #include +#include #define debug 0 +#define FAILED 1 + +// Declare Function +int numcmp (const void *a, const void *b); +float mean(int *num, int length); +float median(int *num, int length); // Comparison function for qsort() int numcmp (const void *a, const void *b) { @@ -30,12 +37,12 @@ float mean(int *num, int length) { // Median function that outputs median float median(int *num, int length){ // If the length of array is even - if(length%2==0){ + if (length%2==0){ //return the average number between two median numbers return (num[length/2-1]+num[length/2])/(float)2; // If the length of array is odd }else{ - // Return the median + // Return the median return num[length/2+1]; } } @@ -74,10 +81,24 @@ int main(int argc, char *argv[]) { for (i=0; i 0){ + fprintf(stdout, "This is parent prcesss(pid:%d)", (int)getpid()); + fprintf(stdout, "The mean is: %f", mean(pt, length)); + fprintf(stdout, "\n%s: FIN. \n",argv[0]); + } return 0; diff --git a/mm.c~ b/mm.c~ index 6c2b9bd..61ca529 100644 --- a/mm.c~ +++ b/mm.c~ @@ -1,7 +1,14 @@ #include #include +#include #define debug 0 +#define FAILED 1 + +// Declare Function +int numcmp (const void *a, const void *b); +float mean(int *num, int length); +float median(int *num, int length); // Comparison function for qsort() int numcmp (const void *a, const void *b) { @@ -12,19 +19,30 @@ int numcmp (const void *a, const void *b) { return 0; } +//Mean functiont that outputs mean of an array float mean(int *num, int length) { + // Initialization of vars + // sum -> sum of ints of array + // i -> num used for doing iteation float sum = 0; int i; + // For loop to add every number to sum for(i=0; i 0){ + fprintf(stdout, "This is parent prcesss(pid:%d)", (int)getpid()); + fprintf(stdout, "The mean is: %f", mean(pt, length)); + } + + // Print FIN fprintf(stdout, "\n%s: FIN. \n", argv[0]); return 0;