Question: LINUX OS, Processes and Inter Process Communication Part 2: Concatenating to files into a third one (12 points): You are asked to write a program
LINUX OS, Processes and Inter Process Communication
Part 2: Concatenating to files into a third one (12 points): You are asked to write a program that generates an output file, the context of which is derived by concatenating the contexts of two input files. Your program will be labeled myfiles and will take two or three arguments. The first and second arguments must be the input files, while the third argument must be the output file. The default name for the output file is myfile.out Note 1 (6 pts): If your program is run without the proper arguments, you must make sure that the proper message appears on screen that guides the user into how many and what sort of arguments are required. If one of the input files provided in the arguments does not exist, then the program must print on screen the corresponding error message. Note 2 (3 pts): Execute your program using OS instruction strace (research on how this works). Copy the output of strace that is produced from your code Note 3 (3 pts): Modify your initial code to support indefinite number of input files. The last argument though is always the output file For your implementation you are expected to use the following functions void WritenFile (int fd, const char *buff, int len): writes data to file descriptor fd void CopyFile (int fd, const char *file_in): writes the contexts from file named file_in to file descriptor fd. WritelnFile is called from within CopyFile Below we provide one example of similar execution $ ./myfiles A1 Usage: ./myfiles file_in 1 file in_2 [file_out (default:myfile.out)] $ ./myfiles A1 A2 A1 No such file or directory $ echo 'Data for file_in_1 This is os 434 Sp19,'> A1 $ echo 'data for file_in_2 but also OS 579 Sp 19!' > A2 $ ./myfiles A1 A2 $ cat myfile.out Data for file in 1 This is OS 434 Sp19, data for file in 2 but also os 579 Sp 19! $ . /myfiles A1 A2 A3 $ cat A3 Data for file_in 1 This is OS 434 Sp19, data for file in 2 but also OS 579 Sp 19! Part 2: Concatenating to files into a third one (12 points): You are asked to write a program that generates an output file, the context of which is derived by concatenating the contexts of two input files. Your program will be labeled myfiles and will take two or three arguments. The first and second arguments must be the input files, while the third argument must be the output file. The default name for the output file is myfile.out Note 1 (6 pts): If your program is run without the proper arguments, you must make sure that the proper message appears on screen that guides the user into how many and what sort of arguments are required. If one of the input files provided in the arguments does not exist, then the program must print on screen the corresponding error message. Note 2 (3 pts): Execute your program using OS instruction strace (research on how this works). Copy the output of strace that is produced from your code Note 3 (3 pts): Modify your initial code to support indefinite number of input files. The last argument though is always the output file For your implementation you are expected to use the following functions void WritenFile (int fd, const char *buff, int len): writes data to file descriptor fd void CopyFile (int fd, const char *file_in): writes the contexts from file named file_in to file descriptor fd. WritelnFile is called from within CopyFile Below we provide one example of similar execution $ ./myfiles A1 Usage: ./myfiles file_in 1 file in_2 [file_out (default:myfile.out)] $ ./myfiles A1 A2 A1 No such file or directory $ echo 'Data for file_in_1 This is os 434 Sp19,'> A1 $ echo 'data for file_in_2 but also OS 579 Sp 19!' > A2 $ ./myfiles A1 A2 $ cat myfile.out Data for file in 1 This is OS 434 Sp19, data for file in 2 but also os 579 Sp 19! $ . /myfiles A1 A2 A3 $ cat A3 Data for file_in 1 This is OS 434 Sp19, data for file in 2 but also OS 579 Sp 19
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
