Professional Documents
Culture Documents
Lab03-1
Lab03-1
Lab # 03
Objectives:
1. Understanding the C compilation process.
2. Getting familiar with simple attributes of binaries
Make a directory named Lab3 on your Desktop and do all following stuff in that
Task 01:
Write a C program to print “Learning Linux is Fun with <your name> ” on stdout
a) Create a preprocessed code file of your source C program.
b) Create an assembly code file of your source C program.
c) Create an object file of your source C program.
d) Create an executable file of your source C program.
Note:
● You must have a clear understanding about each file generated during the compilation process.
● Mention the file formats created during the task.
Note:
You can link statically using --static flag with gcc.
Figure: A process from its creation to execution
The above program mimics the general behavior of “cat”. Compare both files w.r.t sizes and
“strace” both of the statically linked and dynamically linked “cat”. What difference do you see?
Tried strace? Did you get a lot of stuf ��. But don’t worry, just look at openat syscall at line#11 of sample output
given below. Try to understand, why libc is being opened by this binary and not static binary. You can take help from
EdgyEagle.(if he is there)
Figure: strace(ing) a dynamically linked binary
Task 02:
a) Display the “disassembly” of the executable in intel format.
b) Display “Section Headers” of the executable and note down the count of section headers.
c) Display the “Program Headers”
d) Display the “ELF header”.
Task 03:
Perform the following tasks on the cat file compiled in the previous step.
Process Management
Task 01:
a) Write a command to show currently running jobs in your terminal. How can you
get information about all the processes running on your linux OS?
b) Write a command to bring a process to the foreground which is currently running
in background.
c) Write a command to get information about how long the system has been running.
Task 02: Run the sleep command for 50 sec, suspend its execution and then run it in the
background. Execute the program in the background, and then bring it to the foreground.
Meanwhile in another terminal keep checking various statistics of your process using ps(1)
with
–u and –l options.
Figure: Process Life stages that we can control ��