Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Stracing a program

171 bytes added, 16:02, 9 June 2006
Fixed list formatting, added -f description
== What's this stuff about? ==Suppose some program on your system refuses to work or it works,but musch much slower then you've expected. How can you investigate yourself the reasonof such undesirable behaviour? First of all , you can read and analyze logs that this program does (if it does). It's very usefull useful to run unkindly program with<tt>--verbose</tt> argument or somehow else increase the log level, if the program allows that.
But what can you do, if logs are poor and it's impossible to infer the reason of badness from them?
One way is to use strace program to follow system calls performed by given process.
Commonly to use strace you should give the following command:
<ttpre>strace -o strace.out -ff touch /tmp/file</ttpre>
Here * <tt>-o strace.out</tt> option means that strace program will output all investigated informationto the file named <tt>strace.out</tt>; * <tt>touch /tmp/file-ff</tt> is means to strace the forked children of the program with arguments . Child straces outputs will be placed to <tt>strace .out.PID</tt> files, where PID is a pid of the child. If you want all the process under strace (touch in our case) forks child processesoutput to a single file, then, thanks to use <tt>-fff</tt> argument instead (i.e. single <tt>f</tt> option, child processesnot double).are straced too, and ouputs are placed in * <tt>strace.out.PIDtouch /tmp/file</tt> files appropriatelyis the program with arguments which is to be straced.
== Strace results ==
So this is what we have in <tt>strace.out</tt>:
<pre>
execve("/usr/bin/touch", ["touch", "/tmp/file"], [/* 51 vars */]) = 0
</pre>
StraceAnalysis of <tt>strace.out </tt>, in conjunction with reading the source code , is realy very powerfull powerful thing. So Even if you can't analyze not understand strace yurself - output yourself &mdash; send itto the developers, it'll be really helpful.
== Additional notes ==
Sometimes (for example if a program works slow) you are also intersted in time, that the program spends in syscalls. Than
options <tt>-tt</tt> and <tt>-T</tt> are helpful.
As you've seen strace program shows arguments of syscalls. But if arguments are a pointers it shows us only 32 bytes from these pointers.To increase this number use <tt>-s</tt> option. [[Category: Troubleshooting]]