Assignment 6. System call programming and debugging
Useful pointers
Laboratory: Buffered versus unbuffered I/O
As usual, keep a log in the file lab6.txt of what you
do in the lab so that you can reproduce the results later. This should
not merely be a transcript of what you typed: it should be more like a
true lab notebook, in which you briefly note down what you did and
what happened.
For this laboratory, you will implement the same program
using both buffered and unbuffered I/O, and compare the resulting
implementations and performance.
- Write a C program catb.c that uses getchar
and putchar
to copy all the bytes in standard input to standard output. This is
roughly equivalent to the cat
command with no arguments.
- Write a C program catu.c that uses read
and write
to read and write each byte, instead of using getchar and
putchar. The nbyte arguments to
read and write should be 1, so that the
program reads and writes single bytes at a time.
- Use the strace command to compare the system calls
issued by your catb and catu commands (a)
when copying one file to another, and (b) when copying a file to your
terminal. Use a file that contains at least 5,000,000 bytes.
- Use the time
command to measure how much faster one program is, compared to the
other, when copying the same amount of data.
Homework: Binary sort revisited
Rewrite the binsort program you wrote for Homework 6
so that it uses system calls rather than <stdio.h>
to do its I/O. Call the rewritten program
binsortu. Measure any differences in performance between
binsort and binsortu using the
time command.
Submit
Submit the following files.
- The files lab6.txt, catb.c, and
catu.c as described in the lab.
- A single source file binsortu.c as described in the
homework.
- A text file binsort.txt containing the results of
your binsort performance comparison as described in the homework.
All files should be ASCII text files, with no
carriage returns, and with no more than 200 columns per line.
The C source file should contain no more than 132 columns per line.
The shell
commands
expand lab6.txt binsort.txt |
awk '/\r/ || 200 < length'
expand catb.c catu.c binsort.c |
awk '/\r/ || 132 < length'
should output nothing.
© 2005, 2007 Paul Eggert.
See copying rules.
$Id: assign6.html,v 1.3 2007/02/13 00:13:40 eggert Exp $