IPC-2: Prime Calculator
Write a C++ program that passes a number to a child process via an anonymous pipe, computes the m-th prime, and returns it to the parent.
Requirements
- Write a C++ program that creates a child process.
- The main process infinitely waits for the user's input integer m.
- Once number m is received by the main process, it gets passed to the child process via anonymous pipe.
- The child process takes m from the anonymous pipe and calculates the m-th prime number.
- The child process should send the result of the calculation back to the parent process, which, should print it and wait for the next input.
- If the "exit" command is entered, the main process should stop its execution.
Expected result
The resulting application should be able to build and execute from the command line as follows:
make
./prime-calculatorThe typical execution of the program should look like the following:
[Parent] Please enter the number: 8
[Parent] Sending 8 to the child process...
[Parent] Waiting for the response from the child process...
[Child] Calculating 8-th prime number...
[Child] Sending calculation result of prime(8)...
[Parent] Received calculation result of prime(8) = 19...The final solution should contain a Makefile for the multi-stage build. The Makefile should also contain targets all and clean. It's recommended to have compiler and compiler flags declared as Makefile variables. Alternatively, cmake could also be used instead of make.
IPC-1: Signal Echo
Write a C++ program that prints its PID and handles SIGUSR1, reporting the sender's PID, UID and username, and CPU register values.
IPC-3: Shared Array
Implement a C++ shared_array class that shares an integer array between processes by name and size, with operator[] access and semaphore synchronization.