(Solved) : Assignment 1 Process Creation File Operations 40 Points 1 Objectives Practice System Calls Q40028295 . . .

Assignment 1: Process Creation and File Operations (40 Points) 1 Objectives: Practice with system calls to: a) perform file oAssignment 1: Process Creation and File Operations (40 Points) 1 Objectives: Practice with system calls to: a) perform file operations, and b) create and use processes. 2 Description: Overview: You will write a program (says wordcount.c) to find out the number of words in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will create multiple processes with each process being responsible for one file to count its words. The typical format to run the program with input parameters is as follows: ./wordcount File_1 File_2 … File_n Details: First, the program needs to determine the number of files to be processed. This can be argc parameter of the main function; Then, the argv parameter can be used to retrieve the name for each file. After that, fork() system call will be used to create a new child process (just one for now). For this child process, it will simply invoke a function to count the number of words inside its designated file (i.e., child n reads from file n) and print out the result like (note that, no inter-process communication is required as child processes will report i.e., print out their results individually and sequentially, one after another: Child process for File_x: number of words is XXX Each child should wait for its own child to complete before exiting; further, the main process should wait until all child/descendent children processes report their results; then, the main process will report the end of the program with the following message: All n files have been counted! If any of the file names are invalid or could not be open (e.g. due to file system permissions issues), the current child process should terminate immediately, ending the file processing sequence from that point. Don’t worry about communicating this failure up the chain to the parent process; doing so (while not difficult) is outside the scope of this assignment. For word counting, you could simply use the space character as the delimiter. Anything that are not separated by the space will be counted as a single word. For instance, the example “The first program is a Hello world.” will be reported as 6 words (where Hello world is counted as a single word). You could compare your results using the wc utility that is available on Linux machines. Show transcribed image text Assignment 1: Process Creation and File Operations (40 Points) 1 Objectives: Practice with system calls to: a) perform file operations, and b) create and use processes. 2 Description: Overview: You will write a program (says wordcount.c) to find out the number of words in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will create multiple processes with each process being responsible for one file to count its words. The typical format to run the program with input parameters is as follows: ./wordcount File_1 File_2 … File_n Details: First, the program needs to determine the number of files to be processed. This can be argc parameter of the main function; Then, the argv parameter can be used to retrieve the name for each file. After that, fork() system call will be used to create a new child process (just one for now). For this child process, it will simply invoke a function to count the number of words inside its designated file (i.e., child n reads from file n) and print out the result like (note that, no inter-process communication is required as child processes will report i.e., print out their results individually and sequentially, one after another: Child process for File_x: number of words is XXX Each child should wait for its own child to complete before exiting; further, the main process should wait until all child/descendent children processes report their results; then, the main process will report the end of the program with the following message: All n files have been counted! If any of the file names are invalid or could not be open (e.g. due to file system permissions issues), the current child process should terminate immediately, ending the file processing sequence from that point. Don’t worry about communicating this failure up the chain to the parent process; doing so (while not difficult) is outside the scope of this assignment. For word counting, you could simply use the space character as the delimiter. Anything that are not separated by the space will be counted as a single word. For instance, the example “The first program is a Hello world.” will be reported as 6 words (where Hello world is counted as a single word). You could compare your results using the wc utility that is available on Linux machines.

Expert Answer


Answer to Assignment 1: Process Creation and File Operations (40 Points) 1 Objectives: Practice with system calls to: a) perform f…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?