Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. It assumes the file numbers_1.txt contains data as shown below. Addition 1 0 Addition 1 3 Division 1 0 Code in C Thanks! Description

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

2. It assumes the file numbers_1.txt contains data as shown below.

Addition 1 0 Addition 1 3 Division 1 0

image text in transcribed

Code in C Thanks!

Description of assignment: This assignment builds on HW2. Specifically, we will be using interprocess communication (IPC) for communications between the Starter, FileReader, Addition, Subtraction, Multiplication and Division programs. All instances of Addition, Subtraction, Multiplication, and Division should run concurrently. Addition, Subtraction, Multiplication and Division processes/programs will here on be referred to as mathematical processes/programs 1. Starter creates a pipe and forks. T the name of the .txt file as an argument. FileReader will open the file, read the content. In the file, each line has an operation, and a pair of numbers on which the operation should be performed, with a space separating each one of them. FileReader reads all the lines and makes a single string, where each set of the operation the pair of numbers are separated by a space. FileReader then closes the file and then writes the contents to the pipe it inherited. When control returns back to the Starter, it will read the content from the pipe Starter separates each set of operation and pair of numbers. Then for each set, it creates a shared memory segment, and uses the appropriate program to perform the operation on the pair of numbers. Each mathematical process should be running concurrently After the operation, mathematical program writes the name of the operation it performed, pair of the numbers it performed the operation on and the result itself, each separated by a space in the shared memory segment. The Starter then prints out the status information. he child process executes the FileReader program with 2. 3. 4. If there is an operation in the text file that was written twice, for each instance a separate child process should be created. Starter does the following: 1. Create a pipe using the following steps . Create an integer array of size 2 . Use pipe) on the integer array variable created above 2. Send the details to the child process FileReader using the following steps: Create a character array of 200. This is to store the string format of the pipe location. Use sprintf to get the write end of the pipe into the character array Pass the character array to the FileReader as a second argument a fter file name 3. Read the content from the pipe using the following steps Close the writing end, and then read the content from the pipe and close the reading end too. 4. The string is separated into sets, each set consisting of an operation and a pair of numbers on which the operation is to be performed. For each set, it does the following. Creates a shared memory segment of size 256 bytes. Since a shared memory is created for each child, use O CREATE and open in read write mode (O RDWR). It uses mmap to create a pointer to the shared memory. The name of each shared memory should follow the standard as follow: Shared mem0, Shared meml,Shared mem2 Forks a child process to execute the corresponding mathematical operation on the pair of numbers, by passing the operation name, pair of numbers, the file descriptor of the shared memory as arguments to execlp. The operation is performed on the pair of numbers and the required content is written by the mathematical operation into the shared memory .The parent process then reads from the shared memory segment and prints out the appropriate statement. FileReader does the following: . Receives the name of the file and the file descriptor of the write end of the pipe as arguments from the Starter. .Using atoi copies the pipe reference which is the third argument in the argv into an integer variable. Read the contents from the.txt file. .Write the contents into the pipe. Addition, Subtraction, Multiplication and Division each do the following: It receives a pair of numbers and the file descriptor of the shared memory as arguments . from the Starter. Performs the operation on the pair of numbers and writes the name of the operation, the pair of numbers and the result of the operation in to the shared memory. Background: For the background of the assignment, review the related material (sec. 3.5.1 POSIX shared memory and 3.6.3.1 ordinary pipes), the related self-exercise example you ran recently and consult the man pages (shm open0, ftruncate(), mmap(), shm unlink)) as needed. You can simply search for "man shm_ open0" etc. Please note that this is not conventional serial C programming. For this file the output should be as shown below: machine: ./Starter numbers 1.txt Starter: Forked process with ID [41187] Starter: Pipe Read end FD 3 and Pipe write end FD 4 Starter: Waiting for process [41187] Starter: Child process [411871 returned 3 Operations are Addition 1 0 Addition 1 3 Division 1 0 Starter: Forked process with ID [411881 for Addition operation Starter: Name of shared memory is Shared mem0 and FD is 3 Starter: Waiting for process [41188] Starter: Forked process with ID [41189] for Addition operation Starter: Name of shared memory is Shared meml and FD is 4 Starter: Waiting for process [41189]. Starter: Forked process with ID [41190] for Division operation Starter: Name of shared memory is Shared mem2 and FD is 5 Starter: Waiting for process [41190] Addition: Child Process [411891 Addition: Child Process [411881 Starter: Child process [411881 of type Addition operated on 1 and and returned Starter: Child process [41189] of type Addition operated on 1 and 3 and returned Division: Child Process [41190] Starter: Child process [41190] of type Division operated on 1 and and returned undefined Description of assignment: This assignment builds on HW2. Specifically, we will be using interprocess communication (IPC) for communications between the Starter, FileReader, Addition, Subtraction, Multiplication and Division programs. All instances of Addition, Subtraction, Multiplication, and Division should run concurrently. Addition, Subtraction, Multiplication and Division processes/programs will here on be referred to as mathematical processes/programs 1. Starter creates a pipe and forks. T the name of the .txt file as an argument. FileReader will open the file, read the content. In the file, each line has an operation, and a pair of numbers on which the operation should be performed, with a space separating each one of them. FileReader reads all the lines and makes a single string, where each set of the operation the pair of numbers are separated by a space. FileReader then closes the file and then writes the contents to the pipe it inherited. When control returns back to the Starter, it will read the content from the pipe Starter separates each set of operation and pair of numbers. Then for each set, it creates a shared memory segment, and uses the appropriate program to perform the operation on the pair of numbers. Each mathematical process should be running concurrently After the operation, mathematical program writes the name of the operation it performed, pair of the numbers it performed the operation on and the result itself, each separated by a space in the shared memory segment. The Starter then prints out the status information. he child process executes the FileReader program with 2. 3. 4. If there is an operation in the text file that was written twice, for each instance a separate child process should be created. Starter does the following: 1. Create a pipe using the following steps . Create an integer array of size 2 . Use pipe) on the integer array variable created above 2. Send the details to the child process FileReader using the following steps: Create a character array of 200. This is to store the string format of the pipe location. Use sprintf to get the write end of the pipe into the character array Pass the character array to the FileReader as a second argument a fter file name 3. Read the content from the pipe using the following steps Close the writing end, and then read the content from the pipe and close the reading end too. 4. The string is separated into sets, each set consisting of an operation and a pair of numbers on which the operation is to be performed. For each set, it does the following. Creates a shared memory segment of size 256 bytes. Since a shared memory is created for each child, use O CREATE and open in read write mode (O RDWR). It uses mmap to create a pointer to the shared memory. The name of each shared memory should follow the standard as follow: Shared mem0, Shared meml,Shared mem2 Forks a child process to execute the corresponding mathematical operation on the pair of numbers, by passing the operation name, pair of numbers, the file descriptor of the shared memory as arguments to execlp. The operation is performed on the pair of numbers and the required content is written by the mathematical operation into the shared memory .The parent process then reads from the shared memory segment and prints out the appropriate statement. FileReader does the following: . Receives the name of the file and the file descriptor of the write end of the pipe as arguments from the Starter. .Using atoi copies the pipe reference which is the third argument in the argv into an integer variable. Read the contents from the.txt file. .Write the contents into the pipe. Addition, Subtraction, Multiplication and Division each do the following: It receives a pair of numbers and the file descriptor of the shared memory as arguments . from the Starter. Performs the operation on the pair of numbers and writes the name of the operation, the pair of numbers and the result of the operation in to the shared memory. Background: For the background of the assignment, review the related material (sec. 3.5.1 POSIX shared memory and 3.6.3.1 ordinary pipes), the related self-exercise example you ran recently and consult the man pages (shm open0, ftruncate(), mmap(), shm unlink)) as needed. You can simply search for "man shm_ open0" etc. Please note that this is not conventional serial C programming. For this file the output should be as shown below: machine: ./Starter numbers 1.txt Starter: Forked process with ID [41187] Starter: Pipe Read end FD 3 and Pipe write end FD 4 Starter: Waiting for process [41187] Starter: Child process [411871 returned 3 Operations are Addition 1 0 Addition 1 3 Division 1 0 Starter: Forked process with ID [411881 for Addition operation Starter: Name of shared memory is Shared mem0 and FD is 3 Starter: Waiting for process [41188] Starter: Forked process with ID [41189] for Addition operation Starter: Name of shared memory is Shared meml and FD is 4 Starter: Waiting for process [41189]. Starter: Forked process with ID [41190] for Division operation Starter: Name of shared memory is Shared mem2 and FD is 5 Starter: Waiting for process [41190] Addition: Child Process [411891 Addition: Child Process [411881 Starter: Child process [411881 of type Addition operated on 1 and and returned Starter: Child process [41189] of type Addition operated on 1 and 3 and returned Division: Child Process [41190] Starter: Child process [41190] of type Division operated on 1 and and returned undefined

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

V2. stella had wsges of 70000 incomebof 15000 rental loses of 26000

Answered: 1 week ago