Starting from:

$30

Assignment #01 UNIX/LINUX systems

Programming Assignment #01

UNIX/LINUX systems usually include some command that allows you to trace system calls made by a
process. Under Linux, this command is strace. For example, to trace all the system calls made during
execution of “ls” you would type “strace ls”. If the display is too long to fit your screen, you can use
“strace –o out4ls ls” to write your output into file out4ls. Check “man strace” (traditional UNIX manual
pages) or “info strace” (GNU style manual pages) in your Linux system for details. It is a good tool for
learning, either as a light-weight debugger, or as a primitive profiler.
1. (8 points) STRACE a small program. Create your own program in C as follows
#include <stdio.h
int main(void) {
FILE *fd ; float pval=3.14159; int i,k;
If ((fd= fopen("myTstFile","r+"))==NULL)
 printf("\n Program Failed, figure out why...\n");
 else {
 printf("\n Simple pie value %1.8f\n", pval);
for (i=0; i<100; i++) {
 k = rand()%10;
 if (fprintf(fd, "%f\n",pval+i*k)==-1) perror("write err"); fflush(fd);
 printf("."); fflush(stdout);
 }
 fclose(fd); printf("\n Program successful ends\n");
 }
}
a. Without creating file myTstFile (no such a file in your working directory), run “strace yourCode”,
read your output, pick the first five of most frequently invoked system calls and explain which
among the five system calls caused the program to fail.
b. With file myTstFile (a dummy file) being created, run “strace yourCode” again, read your output
to pick the most frequently invoked system call.
c. Is “fopen” a system call? If not, which system call it mainly correlates with?
d. Is “printf” a system call? If not, which system call it mainly correlates with?
2. (2 points) STRACE a Linux utility command -- cal. Run “strace –c cal”, capture the output, and
then pick the top three system calls which consumed the system time and briefly describe their
functionality.
3. (3 bonus points) STRACE/LTRACE Linux utility commands “ls”. Command ltrace is another
tracing tool used for tracing the library function calls. Use both strace and ltrace to Linux
command ls to report what library functions and system calls are used to
a. Open the current directory
b. Get the list of directory entries
c. Print the output to your screen
Note:
1. Correctly answering Question 3 would have 3 bonus points, but the total points of the assignment
is 10. That is, if you get 8 points by answering Question 1&2 and 3 points by answering Question
3, the final score of your assignment is 10 NOT 11.
2. You are going to submit a single PDF or MS WORD file to answer the questions. Please show
your name in every page of your submission, and name your file as
“YourLastName_YourFirstNameInitial_PA1”

More products