CITS2002 Systems Programming | |
|
Workshop 4: File I/O and measuring execution timeIn Lecture 7 we saw how an application program may read a file's contents by making a number of system-calls - notably open(), read(), and close().When a system's currently running process makes an input/output (I/O) request to read a disk-file, the operating system will suspend the execution of the requesting process to permit another process to execute on the processor. This involves saving the current execution state of processes, and managing internal operating system structures - collectively known as a performing a context switch. Of course, all of this takes time, as does the actual transfer of data from the disk-file into main memory. For this exercise we'd like to measure the time taken to open a large file, and to read it into memory. In particular, we'd like to measure (if possible):
On Linux or macOS the file /bin/bash holds the initial instructions and data of the executable bash shell. It's about 1.2MB in size. For this workshop we'll need a much larger file, so we can use our shell (which is a programming language in disguise!) to quickly make 1000 copies of the file (so you'll need about 1GB of spare disk space):
prompt> for i in {1..1000} ; do cat /bin/bash >> /tmp/huge ; done We'd like our program to be configurable without having to recompile it each time, so it should receive two command-line arguments:
Thus we can typically run our program with: prompt> ./readtest /tmp/huge 1000 Run your program several times (averaging the timing results), and with different sized buffers.
BEFORE the workshop session, you're strongly encouraged to think how you would do it. You are not expected to have developed and tested a perfect solution before the workshop, but you should at least scratch out your approach on paper. From the information presented in lectures so far, we should know how to:
|