Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <time.h>
- #include <malloc.h>
- int minValue = 0;
- int maxValue = 0;
- void findMinVal(int *tmpArray, int size)
- {
- int tmp = tmpArray[0];
- int i;
- for(i=1;i<size;i++)
- {
- if(tmp > tmpArray[i])
- {
- tmp = tmpArray[i];
- }
- }
- minValue = tmp;
- }
- void findMaxVal(int *tmpArray, int size)
- {
- int tmp = tmpArray[0];
- int i;
- for(i=1;i<size;i++)
- {
- if(tmp < tmpArray[i])
- {
- tmp = tmpArray[i];
- }
- }
- maxValue = tmp;
- }
- int main(void)
- {
- int *array;
- int cnt = 10 ; //wielkosc tablicy
- int i;
- srand(time(0));
- //#+
- array = (int*)malloc(cnt * sizeof(int));
- for(i=0; i<cnt; i++)
- {
- array[i] = (rand() % 10) + 1;
- }
- //#-
- int status;
- pid_t child1 = fork();
- pid_t child2 = fork();
- if (child1 > 0 && child2 > 0)
- { printf("PARENT: my pid is %d\n", getpid());
- waitpid(child1,&status,0);
- waitpid(child2,&status,0);
- }
- if (child1 == 0)
- {
- printf("Child1: my pid is %d\n", getpid());
- findMinVal(array,cnt);
- exit(0);
- }
- if (child2 == 0)
- {
- printf("Child2: my pid is %d\n", getpid());
- findMaxVal(array,cnt);
- exit(0);
- }
- printf("%d\n", minValue);
- printf("%d\n", maxValue);
- free(array);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement