WRITELOOP

STRACE - LINUX KERNEL TOOL TO MAKE ERROR TRACING ON NATIVE BINARIES OR PYTHON, RUBY, PHP SCRIPTS

2012 August 27

According to wikipedia:

“strace is a debugging utility for Linux and some other Unix-like systems to monitor the system calls used by a program and all the signals it receives, similar to “truss” utility in other Unix systems. This is made possible by a kernel feature known as ptrace”.

“…the most common usage is to start a program using strace, which prints a list of system calls made by the program. This is useful if the program continually crashes, or does not behave as expected; for example using strace may reveal that the program is attempting to access a file which does not exist or cannot be read.An alternative application is to use the -p flag to attach to a running process. This is useful if a process has stopped responding, and might reveal, for example, that the process is blocking whilst attempting to make a network connection. As strace only details system calls it cannot be used to detect as many problems as a code debugger such as GNU Debugger (gdb). It is, however, easier to use than a code debugger, and is an extremely useful tool for system administrators.”

SYNTAX:

$ strace -p [PROCESS_PID]

It can be used to discover exceptions/errors raised by programs written on C and other languages - even python scripts, when also used with the application logs. In the case of python scripts, it can even show an exception that wasn’t raised on the script source code.

It returns as output, on each line, a linux kernel system call (read, write, unlink, close, munmap).

Below there is a cheatsheet on whatever each one of those system calls mean:

http://www.digilife.be/quickreferences/QRC/LINUX%20System%20Call%20Quick%20Reference.pdf