CITS2002 Systems Programming  
 

Unit home

Project 1

help2002

Lecture & Workshop
recordings on LMS

Schedule

FAQ

Unit outline

C textbooks

OS textbooks

Information resources


Extra reading

Past projects

Recent feedback


Working effectively

Look after yourself!

Workshop 4: File I/O and measuring execution time

In 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):

  • the time taken by each system-call, and

  • the time taken to perform read()s into different sized input buffers (character arrays into which we read the file's contents).



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:

  • one to name the required file (as as /tmp/huge), and

  • one to indicate how big its input buffer should be - such as 100bytes, 1000bytes, ....

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.


OPTIONAL: chilli Do you know a simple way to capture the output (execution time information) of your program and to plot it?

 


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:

  • recognize our need to use certain system-calls and constants, and know how to obtain them by using appropriate header files.
  • know how to receive suitable command-line arguments.
  • know how to check the return values of the system-calls, and act appropriately.
  • know how to time the execution of our program. This code, milliseconds.c should help!

So, before the workshop session, think how you can combine this (already known) information to develop a solution.


The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Presented by [email protected]