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 email@example.com. 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 multiple of x which is closest to a^b
- Nth number whose sum of digit is multiple of 10
- Find the largest possible k-multiple set
- Find the largest multiple of 2, 3 and 5
- First N terms whose sum of digits is a multiple of 10
- Smallest integer with digit sum M and multiple of N
- Round the given number to nearest multiple of 10
- Check if a number is multiple of 5 without using / and % operators
- n'th multiple of a number in Fibonacci Series
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Round the given number to nearest multiple of 10 | Set-2
- How to return multiple values from a function in C or C++?