Home / Expert Answers / Computer Science / in-c-please-implement-a-multi-process-linear-search-the-parent-process-shall-load-a-file-of-str-pa464

(Solved): In C++ please(: Implement a multi-process linear search. The parent process shall load a file of str ...



In C++ please(:



Implement a multi-process linear search.
The parent process shall load a file of strings into an array (or a vector), split t
Implement a multi-process linear search. The parent process shall load a file of strings into an array (or a vector), split the array into sections, and then fork off children. Each child process shall search one of the sections of the array, for the specified string. If the child does not find the string, it terminates with the exit code of 1 . Otherwise, it terminates with the exit code of 0. The parent, meanwhile, continuously executes wait(). Whenever, one of the child processes terminates, the wait() will unblock, and the parent process shall check the exit code of the child. The exit status of the child can be checked using the WEXITSTATUS macro as follows: //The variable to hold the exit status int exitstatus; //Other code... if(wait(\&exit status) < 1) \{ perror("wait"); exit(-1); if(WEXITSTATUS(exit status) ) If all children terminate with the code of 1 , then the parent prints "No string found" to the terminal. Otherwise, the parent terminates all child processes and exits. A child process can be terminated using the kill() system call. For example, kill(1234,SIGKILL) will terminate and \#tinclude ; otherwise your program may not compile). Technical Details The program shall be ran using the following command line: ./multi-search KKEY Where is the name of the file containing the strings, is the number of child processes, and is the string to search for. For example, . multi-search strings.txt abcd 10 tells the program to split the task of searching for string abcd in file string.txt among 10 child processes.


We have an Answer from Expert

View Expert Answer

Expert Answer



Step 1: Splitting the Array




First, we need to split the array of strings into sections based on the number of child processes. This step involves creating a function splitArray that takes the original array and the number of processes as input and returns an array of sections.




We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe