May 2017
Beginner
552 pages
28h 47m
English
One way to understand strace is to write a short C program and use strace to see what system calls it makes.
This test program allocates memory, uses the memory, prints a short message, frees the memory, and exits.
The strace output shows the system functions this program calls:
$ cat test.c #include <stdio.h> #include <stdlib.h> #include <string.h> main () { char *tmp; tmp=malloc(100); strcat(tmp, "testing"); printf("TMP: %s\n", tmp); free(tmp); exit(0); } $ gcc test.c $ strace ./a.out execve("./a.out", ["./a.out"], [/* 51 vars */]) = 0 brk(0) = 0x9fc000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc85c7f5000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", ...