Write a program to create 4 processes: parent process and its child process which perform various tasks :
- Parent process count the frequency of a number
- 1st child sort the array
- 2nd child find total even number(s) in a given array
- 3rd child calculate the sum of even numbers in an array
Input : 2, 4, 6, 7, 9, 0, 1, 5, 8, 3 Output : Parent process : the key to be searched is 7 the frequency of 7 is 1 1st child process : the sorted array is 0 1 2 3 4 5 6 7 8 9 2nd child process : Total even no are: 5 3rd child process : the sum is :45
Explanation – Here, we had used fork() function to create 4 processes three child and one parent process. So, here we use two fork() function which create 4 process n1=fork() and n2 = fork()
- if n1 and n2 is greater than zero then it is parent process which counts the frequency of a number.
- if n1 is equal to zero and n2 is greater than zero then it is 1st child process which sorts the given array.
- if n1 is greater than zero and n2 is equal to zero than it is 2nd child process which finds the total even numbers in the array.
- if n1 and n2 both equal to zero then it is 3rd child calculates the sum of all elements in an array.
Parent process : the key to be searched is 7 the frequency of 7 is 1 1st child process : the sorted array is 0 1 2 3 4 5 6 7 8 9 2nd child process : Total even no are: 5 3rd child process : the sum is :45
This article is contributed by Shivani Baghel. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.or
- searching in fork()
- sorting in fork()
- Multiple of x closest to n
- Find the largest possible k-multiple set
- Nth number whose sum of digit is multiple of 10
- Find the largest multiple of 2, 3 and 5
- First N terms whose sum of digits is a multiple of 10
- Find the multiple of x which is closest to a^b
- Minimum Possible sum of digits in a positive multiple of N
- Smallest multiple of 3 which consists of three given non-zero digits
- Check if a number is multiple of 5 without using / and % operators
- n'th multiple of a number in Fibonacci Series
- Smallest N digit number which is a multiple of 5
- Smallest multiple of N formed using the given set of digits
- Find First element in AP which is multiple of given prime