Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this part of the homework assignment, you will be writing another simple C program that creates three child processes, all running concurrentl 1. parent

image text in transcribed

image text in transcribed

In this part of the homework assignment, you will be writing another simple C program that creates three child processes, all running concurrentl 1. parent 1. The main() will access the command line argument - name of a text file. If there is no argument, it should write a usage message (indicating how to use this program) and terminate. Otherwise, it should recover the argument. COMP3300 Page 1 2. In the beginning, you will do the same thing as you did in first step of Part I, ie.. read the list of numbers from the data file and, again, sort the list within the program in ascending order using the same sorting technique as you used in Part I. 3. Now the main) will fork off five child processes using fork ) system call and pass the list to each of the newly created child processes. Call these children child 1, child- child. such that each child process will process ONLY 1/5th of the numbers in the list. However, before passing control to the child processes, the parent process will print the following message I am the father of the followings: . ..,.. .,... ,..., and . . . where . . . represents the process id of each of the five children. HINT: Think of how the child process will know about the first number in the list from which it has to start processing the list, perhaps a pipe or perhaps a simple shared variable will do it? Does it need to know the lasit number too or could it simply finish after processing 25 numbers? Think carefully to come up with the solution.] Will wait for all five of its children to complete On "termination" of each child, will report the event by printing the following message on screen: 4. 5. From the main child, id = ended with status where the first set of dots is the pid of the child and the second set of dots represent the termination status of the child Parent will calculate the CPU time it takes to do the entire set of steps (including that of child processes), print the CPU time and then will terminate after printing the message "Good bye! 6. 13 ii) Children On its turn, each child will start its execution. Each child process will calculate the persistence of each of the number in its portion of the sorted list and will find the number with the smallest and the largest persistence values and print both the numbers and their corresponding persistence values followed by the following message I am kid #: and my id is: Where the first set of dots is the child # (1, 2, 3, 4 or 5) and the second set of dots is the pid of itself. After copying the file, it will terminate its execution with the exit) system call by providing some arbitrary integer m (m>1) as an argument to the exit() system call. What you need to do to finish the assignment: A careful study and understanding of the problem statement and its details Some thoughts and efforts in program design. Looking up the UNLX/LINUX man pages and the auxiliary sources. A careful walk-through of the code to make sure everything is according to specifications described in this handout. General Instructions: Make sure that your program compiles and runs on CS server This is an individual programming assignment I will release a sample ASC test file containing 125 9-digit numbers about 24 hours before the due date. ie., around 10:00 AM on Jan 21, 2019 through the Blackboard site You MUST use list of numbers in this file for final output. However your program development is NOT dependent on the availability of this file. You can create your own sample data file with arbitrary 9 digit numbers In program header, you MUST tell us about yourself (your name, student id, homework number, date, class, etc.) The program MUST include reasonable comments to indicate what you are doing and also MUST include proper white spaces to make it readable In this part of the homework assignment, you will be writing another simple C program that creates three child processes, all running concurrentl 1. parent 1. The main() will access the command line argument - name of a text file. If there is no argument, it should write a usage message (indicating how to use this program) and terminate. Otherwise, it should recover the argument. COMP3300 Page 1 2. In the beginning, you will do the same thing as you did in first step of Part I, ie.. read the list of numbers from the data file and, again, sort the list within the program in ascending order using the same sorting technique as you used in Part I. 3. Now the main) will fork off five child processes using fork ) system call and pass the list to each of the newly created child processes. Call these children child 1, child- child. such that each child process will process ONLY 1/5th of the numbers in the list. However, before passing control to the child processes, the parent process will print the following message I am the father of the followings: . ..,.. .,... ,..., and . . . where . . . represents the process id of each of the five children. HINT: Think of how the child process will know about the first number in the list from which it has to start processing the list, perhaps a pipe or perhaps a simple shared variable will do it? Does it need to know the lasit number too or could it simply finish after processing 25 numbers? Think carefully to come up with the solution.] Will wait for all five of its children to complete On "termination" of each child, will report the event by printing the following message on screen: 4. 5. From the main child, id = ended with status where the first set of dots is the pid of the child and the second set of dots represent the termination status of the child Parent will calculate the CPU time it takes to do the entire set of steps (including that of child processes), print the CPU time and then will terminate after printing the message "Good bye! 6. 13 ii) Children On its turn, each child will start its execution. Each child process will calculate the persistence of each of the number in its portion of the sorted list and will find the number with the smallest and the largest persistence values and print both the numbers and their corresponding persistence values followed by the following message I am kid #: and my id is: Where the first set of dots is the child # (1, 2, 3, 4 or 5) and the second set of dots is the pid of itself. After copying the file, it will terminate its execution with the exit) system call by providing some arbitrary integer m (m>1) as an argument to the exit() system call. What you need to do to finish the assignment: A careful study and understanding of the problem statement and its details Some thoughts and efforts in program design. Looking up the UNLX/LINUX man pages and the auxiliary sources. A careful walk-through of the code to make sure everything is according to specifications described in this handout. General Instructions: Make sure that your program compiles and runs on CS server This is an individual programming assignment I will release a sample ASC test file containing 125 9-digit numbers about 24 hours before the due date. ie., around 10:00 AM on Jan 21, 2019 through the Blackboard site You MUST use list of numbers in this file for final output. However your program development is NOT dependent on the availability of this file. You can create your own sample data file with arbitrary 9 digit numbers In program header, you MUST tell us about yourself (your name, student id, homework number, date, class, etc.) The program MUST include reasonable comments to indicate what you are doing and also MUST include proper white spaces to make it readable

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

What are the roles and responsibilities for SITE accountability?

Answered: 1 week ago