Hey thanks,
maybe u can help me with another problem..
I am try to create 2 children
Each of them will sort half of the array.
for exemple:
my array: 1,0,5,2,8,6,9,10
the first child will sort 1,0,5,2 to 0,1,2,5
the second child will sort 8,6,9,10 to 6,8,9,10
my idea was : to send to qsort the 2 parts separately.
after both finish' the father will do merge..
i wrote a working megre func', and also the comp func-that the qsort use is working.
here is my output , so i can see that it sucsseed to sort the first half.. but why not the other ...and why 3 forks ???
output:
pfork pfork
pfork 0 1 2 5 8 6 9 10
1 0 5 2 8 6 9 10
to that code:
Code:
01 for(k=0;k<2;k++){
02 pfork = fork ();// fork kid
03 if ( pfork == -1 ){//fork failed
04 perror("fork");
05 exit (3);
06 }
07 if (pfork==0){//only kid
08 printf("pfork ");
09 qsort(arr+(k*(4)),4,sizeof arr[0],comp);
10
11 }
12 }
13
14 if (pfork!=0)
15 for ( q = 0; q < p; q++ )
16 wait(NULL);
17
merge(arr);
18 if(pfork!=0)
19 for( i =0 ; i<n; i++)
20 printf("%d ",arr[i]);
thanx!