Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: C The goal of this homework is to become familiar with the environment in hoare while practicing system calls. We will be using getopt

Language: C
image text in transcribed
image text in transcribed
The goal of this homework is to become familiar with the environment in hoare while practicing system calls. We will be using getopt and perror as well as fork0 This project is just reading some integers from an input file and writing them out in reverse order into the output file. All that is required of you is to use fork . parsing the options, and using perror Your project should consist of one program, which will fork off versions of itself to do some file processing. It will start by using some command line arguments. You must implement at least the following command line arguments using getopt: -i inputfilename -o outputfilename The -h option will display all legal command line options and how it is expected to run, as well as the default behavior. If input and output filenames are not specified, the defaults should be input.dat and out put.dat Once you have parsed the command line arguments and validated them, then you should attempt to open the input file. The input file should start with a number on a line by itself, with that number indicating the amount of times you will be required to do a task with copies of your process using fork. Each task list will follow in the file, which will consist of an integer on one line (representing the amount of numbers that will follow) and that many numbers. An example of this input file is below: 3 6 107 8137 1 3 50 4 7 53 5789 The main process (parent) should read the first line of the file. Once it has read that line, it should then go into a loop based on that number, with each iteration of the loop forking off a copy that will then process the next two lines. Once that child has finished its work (defined below), it will write some data to the output file and then terminate. At that point, as the parent detects its child has terminated, it should do another iteration of the loop until done. After all children have terminated. the parent should write the PIDs of all of its children that it launched, as well as its own PID to the output file When a child process starts, it should read the next line of the file, which will tell it how many numbers to read afterwards. We see in our example file that the first forked child would read a 6. It should then read that number of integers and put them into a stack. After putting all of the numbers into a stack, the child should write its PID to the output file, followed by those numbers in reverse order. For example: 13278: 7318 107 63 After this has been done with the example file given above, we would expect an output file to look as below (with different PIDs, of course): 13278: 7 3 1 8 107 6 13281: 4 50 3 1 13294:1 987535 All children were: 13278 13281 13294 I'll like some meaningful error messages. The format for error messages should be: logParse: Error: Detailed error message where logParse is actually the name of the executable (argv t01) that you are trying to execute. These error messages should be sent to stderr using perror The goal of this homework is to become familiar with the environment in hoare while practicing system calls. We will be using getopt and perror as well as fork0 This project is just reading some integers from an input file and writing them out in reverse order into the output file. All that is required of you is to use fork . parsing the options, and using perror Your project should consist of one program, which will fork off versions of itself to do some file processing. It will start by using some command line arguments. You must implement at least the following command line arguments using getopt: -i inputfilename -o outputfilename The -h option will display all legal command line options and how it is expected to run, as well as the default behavior. If input and output filenames are not specified, the defaults should be input.dat and out put.dat Once you have parsed the command line arguments and validated them, then you should attempt to open the input file. The input file should start with a number on a line by itself, with that number indicating the amount of times you will be required to do a task with copies of your process using fork. Each task list will follow in the file, which will consist of an integer on one line (representing the amount of numbers that will follow) and that many numbers. An example of this input file is below: 3 6 107 8137 1 3 50 4 7 53 5789 The main process (parent) should read the first line of the file. Once it has read that line, it should then go into a loop based on that number, with each iteration of the loop forking off a copy that will then process the next two lines. Once that child has finished its work (defined below), it will write some data to the output file and then terminate. At that point, as the parent detects its child has terminated, it should do another iteration of the loop until done. After all children have terminated. the parent should write the PIDs of all of its children that it launched, as well as its own PID to the output file When a child process starts, it should read the next line of the file, which will tell it how many numbers to read afterwards. We see in our example file that the first forked child would read a 6. It should then read that number of integers and put them into a stack. After putting all of the numbers into a stack, the child should write its PID to the output file, followed by those numbers in reverse order. For example: 13278: 7318 107 63 After this has been done with the example file given above, we would expect an output file to look as below (with different PIDs, of course): 13278: 7 3 1 8 107 6 13281: 4 50 3 1 13294:1 987535 All children were: 13278 13281 13294 I'll like some meaningful error messages. The format for error messages should be: logParse: Error: Detailed error message where logParse is actually the name of the executable (argv t01) that you are trying to execute. These error messages should be sent to stderr using perror

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions