COMP 3000 Lab 3 2012

From Soma-notes

Instructions

This lab is still being revised

In this lab you will examine how processes interact with the dynamic linker and the kernel.

You may use any machine running Ubuntu 12.04 or equivalent. You may need to install software if a given utility is not already installed; other than that, you do not need administrative access to the machine.

You should expect to complete Part A in tutorial. You should submit the answers to both Part A and Part B, however, on Friday.

Indicate where you got the information to answer each question. This can be as simple as "the TA told me" or instead "I looked at chapter 7 in book X" or, just, "man page for ls". If you do not include such information, you'll automatically have 10 points deducted from your grade.

You should turn in Lab 3 by 10 PM on Friday, October 12 via cuLearn. Your answers should be in plain text (the true UNIX file format) or PDF. No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format). This lab has ?? points in total.

Part A

  1. [1] Compile the program hello.c (below) with gcc -O hello.c -o hello-dyn and then run it using the command ltrace ./hello-dyn . What dynamic functions does the program call?
  2. [1] Compile the same program with gcc -O -static hello.c -o hello-static . Run this second binary with ltrace as before. What dynamic functions does the program now call?
  3. [2] Run strace on the static and dynamically compiled versions of hello. How many system calls do they each produce?
  4. [1] How can you make the output of hello.c go to the file "hello-output" by changing how it is invoked at the command line?
  5. [1] How can you make the output of hello.c go to the file "hello-output" by changing its code?
/* hello.c */
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
       printf("Hello, world!\n");
       return 0;
}

Part B

  1. [2] Why do we "open" files? Specifically, to what extent is it possible to do file I/O without open and close operations - assuming you could change the UNIX API?
  2. [2] What is the relationship between dynamic library calls and system calls?