Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

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", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985