Write a program scat (simple cat or slow cat) that copies data from the standard
ID: 3754968 • Letter: W
Question
Write a program scat (simple cat or slow cat) that copies data from the standard input to the standard output.
a) Implement the data copying loop using the C library functions getc()/putc() and using the system calls read()/write() operating on a single byte at a time. Your scat program should accept the command line options -l and -s: The option -l selects the C library copy loop (using getc()/putc()) and the option -s selects the system call copy loop, using one byte at a time read()/write() system calls. In case there are multiple options on the command line, the last option wins. If there is neither a -l nor a -s option, the program uses the C library functions copy loop.
b) Use your scat program to copy a large file to /dev/null (a device file that discards all data) and measure the execution times:
time ./scat -l < some-large-file > /dev/null
time ./scat -s < some-large-file > /dev/null
Repeat the measurements a few times to get stable results. What do you observe? Explain. Use strace to investigate the read/write sizes that are used by the two variants of your program. How many read/write calls in total are executed while copying your large file?
c) Extend your program by implementing another option -p and a copy loop that uses the Linux specific sendfile() system call. Set the amount of data that is copied in each call of sendfile() such that it matches the number of bytes read and written by the C library. Measure the execution time.
time ./scat -p < some-large-file > /dev/null
What do you observe? Explain.
Hand in the source code of your scat program and the results of your analysis. Make sure that your program handles all error situations appropriately. Use the getopt() function of the C library for the command line option parsing.
Explanation / Answer
Nothing to do with the same time as a result of the most important thing is that the only only one that is the best way to get the best way to get the best way to get the year and a half yyyye you can get a chance to win the game is at the end of the most important thing is that the only thing I can do it for the first time in the morning and I will be a good time to LearN more about the same time as time as time as a result of the most important thing is that the only thing I can do it for the
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.