Homework #2 – Using strace to spy on system calls [30 pts]


You are expected to do your own work on all homework assignments.(See the statement of Academic Dishonesty on the Syllabus.)

Check the Syllabus for the late assignment policy for this course.

How to turn in?

Assignments need to be turned in via Laulima. Check the Syllabus for the late assignment policy for the course.

What to turn in?

You should turn in single plain text file named README.txt with your answers to the assignment’s questions. Your file must be readable “as is” and points will be removed if the report is not readable.


Environment

For this assignment you need a Linux environment (see Assignment #0).

Hints


Exercise #1: Counting system calls in “Hello World” programs [10 pts]

In this question, you use strace to investigate the system calls placed when running HelloWorld programs in C and Java, i.e., programs that do nothing at all. Download the following two programs to your Linux box:

(To install java on Ubuntu: sudo apt-get install openjdk-8-jdk)

Use the strace tool we have mentioned in class, with the following command-line options for each program:

strace -xf -otracefile_java java HelloWorld

and

strace -xf -otracefile_c ./HelloWorld

The list of system calls (with argument values and return values) will be output into the trace files once each command completes. You can read the manual page for strace (type man strace) to find out what other command-line arguments are available.

WARNING: Some lines in the strace output may appear with the word “resumed” in them, or with a message like “+++ exited with 0 +++”; IGNORE these lines.

Question #1 [3 pts]:

In your report give how many system calls are placed in total by each HelloWorld program, and briefly explain how you counted them (e.g., if using the command-line, just give the command(s) you used). Why do you think these numbers are so different?

Question #2 [3 pts]:

How many different system calls (i.e., counting only one occurrence of a particular system call) are placed by each HelloWorld program? Briefly describe how you obtained this information.

Question #3 [4 pts]:

Based on your intuition and on reading man pages (make sure you read the correct man page, e.g. man 2 write and not man write), and on the strace output, for each of the broad “OS management” areas below give in your report the name of 2 system calls (8 total) placed by the Java HelloWorld program that fall in this area:


Exercise #2 [20 pts]: Is wget getting what it’s asking for?

The /usr/bin/wget system program is used to download files from a Web site given a URL, all on the command-line (To install wget on Ubuntu: sudo apt-get install wget).

Like any program that does I/O, wget does buffering: repeatedly reading chunks of bytes from the “source” into a buffer (i.e., an array of bytes in RAM) and writing these bytes to some “destination”. In the case of wget, the source is the network (i.e., the Web server) and the destination is the local disk (i.e., the file). As you might expect, reading is done with the read system call, and writing is done with the write system call.

Conveniently, Peter Norvig hosts a large (6.2 MiB) text file at: http://norvig.com/big.txt. Use the provided output from strace and wget to answer the following questions. Explain the methods used to answer each question (commands/arguments) and included any interesting observations. You must use command line tools to answer the questions. The norgiv_outfile file was downloaded from the Norvig server and the uh_outfile file was downloaded from a server at UH.

WARNING: Some lines in the strace output may appear with the word “resumed” in them, or with a message like “+++ exited with 0 +++”; IGNORE these lines. You do not have to run wget or strace for the following questions. You must use the provided strace output files.

Answer the following questions using norvig_outfile:

Answer the following questions using uh_outfile: