Question
Write a C or C++ concurrent Shearsort program using basic UNIX system calls for process creation and interprocess communication. You will use system calls such
Write a C or C++ concurrent Shearsort program using basic UNIX system calls for process creation and interprocess communication. You will use system calls such as fork(2), pipe(2), read(2), and write(2) to implement the Shearsort algorithm on multiple UNIX processes (note that the “(2)” in “fork(2)” refers to the section number of the man pages where it can be found). Furthermore, you are to use UNIX message queues to handle the output of the program as explained below.
You need to create one process for each column and one for each row. Hence, there are 2n processes for n × n elements.
1. Initialize the message queue.
2. Read 16 integers from stdin into a 2-dimensional array. This can be done by the main (parent) program.
3. Print the 16 integers in the original order to stdout.
4. Create pipes by means of the pipe system call for communication between processes. Launch all processes by means of the fork() system call. To handle 16 integers, you will launch 8 processes. Initialize each process of the odd phase by having the main program send each row process its associated four numbers.
5. Perform the required number of odd and even phases, using Bubble Sort in each phase.
6. After the sort has finished, send the array of sorted integers to the message queue. Make sure you do not leave any unterminated forked processes in the system.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Creating a concurrent Shearsort program in CC using UNIX system calls involves managing multiple processes and coordinating communication between them ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started