Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Operating System (C Language, Linux) contents of number.txt 1 2 3.5 0 4 You will develop a program avg_many that is given a list of

Operating System (C Language, Linux)

contents of number.txt

1

2

3.5

0

4

You will develop a program avg_many that is given a list of files on the command line. You will need to average up all of the floating-point numbers in all of the files to produce a single average.

Assume that you have text files with numbers separated by newlines. You want to read the numbers in from all the files. Since you want to be flexible on the type and size of numbers your program can handle, you should use double floating-point.

If a file appears multiple times on the command line, those numbers will be processed multiple times.

You should use fork() to start a process for each of the files so that we can compute sums and counts in parallel. To communicate between processes you will use pipe(). You need to wait for all the processes to finish using wait().

You must be able to handle files with any number of numbers (including no numbers). You can assume that the files are well-formed: they will contain only valid numbers separated by newlines.

For example, numbers.txt contains a list of numbers that average to 2.1. running

./avg_many numbers.txt

will output

2.1000
./avg_many numbers.txt numbers.txt

will also output

2.1000
./avg_many numbers.txt morenumbers.txt

will output (assuming morenumbers.txt just has the number 1.0)

1.9166

(trailing zeros are ok.)

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago