Fork Pipe This assignment gives the programmer experience with forking to create another process. Pipes are used to comm

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Fork Pipe This assignment gives the programmer experience with forking to create another process. Pipes are used to comm

Post by answerhappygod »

Fork Pipe This Assignment Gives The Programmer Experience With Forking To Create Another Process Pipes Are Used To Comm 1
Fork Pipe This Assignment Gives The Programmer Experience With Forking To Create Another Process Pipes Are Used To Comm 1 (335.96 KiB) Viewed 26 times
Fork Pipe This assignment gives the programmer experience with forking to create another process. Pipes are used to communicate between the parent process and the child process. This assignment will specify what the parent process and the child process requirements are in the program. General Program Requirements Use a common try-catch mechanism with c-string throws when checking for errors. All arrays that require a size declarator should be of size declarator of 1000. Use global constants for use by the program. Use FILE and the f file commands for all file operations. Build using g++. Name the main program forkpipe.cpp. Name the run execution file forkpipe. Main Program Program Command Line The source code file shall be named forkpipe.cpp. The run file shall be named forkpipe. The running program will accept from the command line one argument number: ./forkpipe <number> example: ./forkpipe 2 The program must check to make sure that one number argument is provided. If this is not the case then an appropriate error message using a throw. Quotes File The quotes file is located at: ~smd013000/courses/3377/assigns/03/quotes.txt Use a function with the following prototype header to create an array that holds quote lines read in from a provided text file named quotes.txt. Quotes Array getQuotesArray () lines : the array that holds cstring quote lines from the quotes.txt file. nolines passes back the number of lines in the array void getQuotes Array (char *lines[], unsigned &no Lines)
Pipes Create 2 pipes used for parent child communication that return a status variable. Use throws to check the return status to make sure the pipes were created without error. Create Another Process Fork Pipe Use fork(); Based on the pid returned by fork() determine if the process is the parent process or the child process. Processes Display all message activities as shown in the run sample at the end of this document. Parent Process As usual the process must close unnecessary part of pipes that are not used. Create a character array for the Parent Read Child Message to hold messages from the child. Design a loop that uses the command line argument number set at the program beginning to indicate how many Get Quote messages to send to the child. Inside the loop: Send using a write to the Parent Write Child Read pipe a Get Quote message to the child. Declare a character array of the correct size and clear it. Use a read of the Parent Read Child Write pipe to get a Quote message from the child. When the loop is done write to the Parent Write Child Read pipe an Exit message. Close the pipes the parent used. Display that the parent is done.
Child Process As usual the process must close unnecessary part of pipes that are not used. Seed a random number generator. Design an infinite loop. Inside the Loop: ● Read the received message from the parent. Determine what the message is: If the message is an Exit ● Leave the infinite loop. If the message is Get Quote Use random number generator to get a random quote line from the quote array. Declare and clear a char send array using correct size Copy to the send array from quote array. Write this quote to the parent. ● ● ● Fork Pipe If the message is invalid Submittal Display to the screen that the message is invalid and sent back to the parent Write this invalid message to the parent. Close the pipes the child used. Display to the screen a that the child is done. Activities File After done designing and testing, capture the run results in an activities text file named forkpipe.txt. Use the copy and paste to local editor text file for creating the forkpipe.txt file. Do not use script or terminal session to create the forkpipe.txt file. See the sample run below. Put in a zip folder that you name: forkpipe.cpp forkpipe.txt Submit what ever you called the .zip folder to blackboard.
Fork Pipe {cslinux1:~/courses/3377/assigns/03/forkpipe} {cslinux1:~/courses/3377/assigns/03/forkpipe} Where is the number argument, I will expire now... {cslinux1:~/courses/3377/assigns/03/forkpipe} ./forkpipe 2 g++ forkpipe.cpp -o forkpipe ./forkpipe In Parent: Write to pipe getQuoteMessage sent Message: Get Quote In Child: Read from pipe pipeParentWriteChildMessage read Message: Get Quote In Child Write to pipe pipeParentReadChildMessage sent Message: "Art is not what you see, but what you make others see." ~ Edgar Degas In Parent: Read from pipe pipeParentReadChildMessage read Message: "Art is not what you see, but what you make others see." ~ Edgar Degas In Parent: Write to pipe getQuoteMessage sent Message: Get Quote In Child: Read from pipe pipeParentWriteChildMessage read Message: Get Quote In Child Write to pipe pipe Parent ReadChildMessage sent Message: "No act of kindness, however small, is ever wasted" ~Aesop In Parent: Read from pipe pipeParentReadChildMessage read Message: "No act of kindness, however small, is ever wasted" ~Aesop In Parent: Write to pipe ParentWriteChild ExitMessage sent Message: Exit Parent Done In Child: Read from pipe pipeParentWriteChildMessage read Message: Exit Child Done {cslinux1:~/courses/3377/assigns/03/forkpipe}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply