blob: ec03e9ab9fe1ab030fe056ccb0e2b7c2d5a5ac54 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001.\" Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
2.\" Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
3.\" Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. The name of the author may not be used to endorse or promote products
15.\" derived from this software without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.\" $Id$
29.\"
30.de CW
31.sp
32.nf
33.ft CW
34..
35.de CE
Wichert Akkerman8829a551999-06-11 13:18:40 +000036.ft R
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037.fi
38.sp
39..
Dmitry V. Levina7835e62010-03-31 17:26:49 +000040.TH STRACE 1 "2010-03-30"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041.SH NAME
42strace \- trace system calls and signals
43.SH SYNOPSIS
44.B strace
45[
Andreas Schwabb87d30c2010-06-11 15:49:36 +020046.B \-CdDffhiqrtttTvxx
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047]
48[
49.BI \-a column
50]
51[
52.BI \-e expr
53]
54\&...
55[
56.BI \-o file
57]
58[
59.BI \-p pid
60]
61\&...
62[
63.BI \-s strsize
64]
65[
66.BI \-u username
67]
68[
Roland McGrath4417fda2003-01-24 04:31:20 +000069.BI \-E var=val
70]
71\&...
72[
73.BI \-E var
74]
75\&...
76[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077.I command
78[
79.I arg
80\&...
81]
82]
83.sp
84.B strace
85.B \-c
86[
Andreas Schwabb87d30c2010-06-11 15:49:36 +020087.B \-D
88]
89[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090.BI \-e expr
91]
92\&...
93[
94.BI \-O overhead
95]
96[
97.BI \-S sortby
98]
99[
100.I command
101[
102.I arg
103\&...
104]
105]
106.SH DESCRIPTION
107.IX "strace command" "" "\fLstrace\fR command"
108.LP
109In the simplest case
110.B strace
111runs the specified
112.I command
113until it exits.
114It intercepts and records the system calls which are called
115by a process and the signals which are received by a process.
116The name of each system call, its arguments and its return value
117are printed on standard error or to the file specified with the
118.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +0000119option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120.LP
121.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000122is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +0000123System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124it invaluable for solving problems with
125programs for which the source is not readily available since
126they do not need to be recompiled in order to trace them.
127Students, hackers and the overly-curious will find that
128a great deal can be learned about a system and its system calls by
129tracing even ordinary programs. And programmers will find that
130since system calls and signals are events that happen at the user/kernel
131interface, a close examination of this boundary is very
132useful for bug isolation, sanity checking and
133attempting to capture race conditions.
134.LP
135Each line in the trace contains the system call name, followed
136by its arguments in parentheses and its return value.
137An example from stracing the command ``cat /dev/null'' is:
138.CW
139open("/dev/null", O_RDONLY) = 3
140.CE
141Errors (typically a return value of \-1) have the errno symbol
142and error string appended.
143.CW
144open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
145.CE
146Signals are printed as a signal symbol and a signal string.
147An excerpt from stracing and interrupting the command ``sleep 666'' is:
148.CW
149sigsuspend([] <unfinished ...>
150--- SIGINT (Interrupt) ---
151+++ killed by SIGINT +++
152.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000153If a system call is being executed and meanwhile another one is being called
154from a different thread/process then
155.B strace
156will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000157being
158.IR unfinished .
159When the call returns it will be marked as
160.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000161.CW
162[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
163[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
164[pid 28772] <... select resumed> ) = 1 (in [3])
165.CE
166Interruption of a (restartable) system call by a signal delivery is processed
167differently as kernel terminates the system call and also arranges its
168immediate reexecution after the signal handler completes.
169.CW
170read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
171--- SIGALRM (Alarm clock) @ 0 (0) ---
172rt_sigreturn(0xe) = 0
173read(0, ""..., 1) = 0
174.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175Arguments are printed in symbolic form with a passion.
Roland McGrath0411b402003-10-22 06:16:32 +0000176This example shows the shell performing ``>>xyzzy'' output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000177.CW
178open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
179.CE
180Here the three argument form of open is decoded by breaking down the
181flag argument into its three bitwise-OR constituents and printing the
182mode value in octal by tradition. Where traditional or native
183usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000184In some cases,
185.B strace
186output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187.LP
188Structure pointers are dereferenced and the members are displayed
189as appropriate. In all cases arguments are formatted in the most C-like
190fashion possible.
191For example, the essence of the command ``ls \-l /dev/null'' is captured as:
192.CW
193lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
194.CE
195Notice how the `struct stat' argument is dereferenced and how each member is
196displayed symbolically. In particular, observe how the st_mode member
197is carefully decoded into a bitwise-OR of symbolic and numeric values.
198Also notice in this example that the first argument to lstat is an input
199to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000200arguments are not modified if the system call fails, arguments may not
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000201always be dereferenced. For example, retrying the ``ls \-l'' example
202with a non-existent file produces the following line:
203.CW
204lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
205.CE
206In this case the porch light is on but nobody is home.
207.LP
208Character pointers are dereferenced and printed as C strings.
209Non-printing characters in strings are normally represented by
210ordinary C escape codes.
211Only the first
212.I strsize
213(32 by default) bytes of strings are printed;
214longer strings have an ellipsis appended following the closing quote.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000215Here is a line from ``ls \-l'' where the
216.B getpwuid
217library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218.CW
219read(3, "root::0:0:System Administrator:/"..., 1024) = 422
220.CE
221While structures are annotated using curly braces, simple pointers
222and arrays are printed using square brackets with commas separating
223elements. Here is an example from the command ``id'' on a system with
224supplementary group ids:
225.CW
226getgroups(32, [100, 0]) = 2
227.CE
228On the other hand, bit-sets are also shown using square brackets
229but set elements are separated only by a space. Here is the shell
230preparing to execute an external command:
231.CW
232sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
233.CE
234Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
235In some cases the bit-set is so full that printing out the unset
236elements is more valuable. In that case, the bit-set is prefixed by
237a tilde like this:
238.CW
239sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
240.CE
241Here the second argument represents the full set of all signals.
242.SH OPTIONS
243.TP 12
244.TP
245.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000246Count time, calls, and errors for each system call and report a summary on
247program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000248running in the kernel) independent of wall clock time. If
249.B \-c
250is used with
251.B \-f
252or
253.B \-F
254(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000256.B \-C
257Like
258.B \-c
259but also print regular output while processes are running.
260.TP
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200261.B \-D
262(Not available on SVR4 and FreeBSD.)
263Run tracer process as a detached grandchild, not as parent of the
264tracee. This reduces the visible effect of
265.B strace
266by keeping the tracee a direct child of the calling process.
267.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000269Show some debugging output of
270.B strace
271itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272.TP
273.B \-f
274Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000275processes as a result of the
276.BR fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000277system call.
278.IP
279On non-Linux platforms the new process is
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280attached to as soon as its pid is known (through the return value of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000281.BR fork (2)
282in the parent process). This means that such children may run
283uncontrolled for a while (especially in the case of a
284.BR vfork (2)),
285until the parent is scheduled again to complete its
286.RB ( v ) fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000287call. On Linux the child is traced from its first instruction with no delay.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000288If the parent process decides to
289.BR wait (2)
290for a child that is currently
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291being traced, it is suspended until an appropriate child process either
292terminates or incurs a signal that would cause it to terminate (as
293determined from the child's current signal disposition).
Roland McGrath41c48222008-07-18 00:25:10 +0000294.IP
295On SunOS 4.x the tracing of
296.BR vfork s
297is accomplished with some dynamic linking trickery.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298.TP
299.B \-ff
300If the
301.B \-o
302.I filename
303option is in effect, each processes trace is written to
304.I filename.pid
305where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000306This is incompatible with
307.BR \-c ,
308since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309.TP
310.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000311This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000312.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313.TP
314.B \-h
315Print the help summary.
316.TP
317.B \-i
318Print the instruction pointer at the time of the system call.
319.TP
320.B \-q
321Suppress messages about attaching, detaching etc. This happens
322automatically when output is redirected to a file and the command
323is run directly instead of attaching.
324.TP
325.B \-r
326Print a relative timestamp upon entry to each system call. This
327records the time difference between the beginning of successive
328system calls.
329.TP
330.B \-t
331Prefix each line of the trace with the time of day.
332.TP
333.B \-tt
334If given twice, the time printed will include the microseconds.
335.TP
336.B \-ttt
337If given thrice, the time printed will include the microseconds
338and the leading portion will be printed as the number
339of seconds since the epoch.
340.TP
341.B \-T
342Show the time spent in system calls. This records the time
343difference between the beginning and the end of each system call.
344.TP
345.B \-v
346Print unabbreviated versions of environment, stat, termios, etc.
347calls. These structures are very common in calls and so the default
348behavior displays a reasonable subset of structure members. Use
349this option to get all of the gory details.
350.TP
351.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000352Print the version number of
353.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000354.TP
355.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000356Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000357.TP
358.B \-xx
359Print all strings in hexadecimal string format.
360.TP
361.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000362Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363.TP
364.BI "\-e " expr
365A qualifying expression which modifies which events to trace
366or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000367.RS 15
368.IP
369[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
370.RE
371.IP
372where
373.I qualifier
374is one of
375.BR trace ,
376.BR abbrev ,
377.BR verbose ,
378.BR raw ,
379.BR signal ,
380.BR read ,
381or
382.B write
383and
384.I value
385is a qualifier-dependent symbol or number. The default
386qualifier is
387.BR trace .
388Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000389.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000390means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000391.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000392which in turn means trace only the
393.B open
394system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000395.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000396means to trace every system call except
397.BR open .
398In addition, the special values
399.B all
400and
401.B none
402have the obvious meanings.
403.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000405expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406the exclamation point with a backslash.
407.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000408\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409Trace only the specified set of system calls. The
410.B \-c
411option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000412to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000413.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000414means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415trace those four system calls. Be careful when making inferences
416about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000417are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000418.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000420.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421Trace all system calls which take a file name as an argument. You
422can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000423.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424which is useful to seeing what files the process is referencing.
425Furthermore, using the abbreviation will ensure that you don't
426accidentally forget to include a call like
427.B lstat
428in the list. Betchya woulda forgot that one.
429.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000430.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431Trace all system calls which involve process management. This
432is useful for watching the fork, wait, and exec steps of a process.
433.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000434.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435Trace all the network related system calls.
436.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000437.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438Trace all signal related system calls.
439.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000440.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441Trace all IPC related system calls.
442.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000443.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000444Trace all file descriptor related system calls.
445.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000446\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000448The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000449.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000450The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000452option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000453.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000455\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000457default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000458.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000460\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000461Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462This option has the effect of causing all arguments to be printed
463in hexadecimal. This is mostly useful if you don't trust the
464decoding or you need to know the actual numeric value of an
465argument.
466.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000467\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000468Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000469.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000470For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000471.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000472(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000473.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000474causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000476\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000477Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000479all input activity on file descriptors
480.I 3
481and
482.I 5
483use
484\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000485Note that this is independent from the normal tracing of the
486.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000488.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000490\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000491Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000493all output activity on file descriptors
494.I 3
495and
496.I 5
497use
498\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000499Note that this is independent from the normal tracing of the
500.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000502.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503.TP
504.BI "\-o " filename
505Write the trace output to the file
506.I filename
507rather than to stderr.
508Use
509.I filename.pid
510if
511.B \-ff
512is used.
513If the argument begins with `|' or with `!' then the rest of the
514argument is treated as a command and all output is piped to it.
515This is convenient for piping the debugging output to a program
516without affecting the redirections of executed programs.
517.TP
518.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000519Set the overhead for tracing system calls to
520.I overhead
521microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522This is useful for overriding the default heuristic for guessing
523how much time is spent in mere measuring when timing system calls using
524the
525.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000526option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000527program run without tracing (using
528.BR time (1))
529and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000531.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532.TP
533.BI "\-p " pid
534Attach to the process with the process
535.SM ID
536.I pid
537and begin tracing.
538The trace may be terminated
539at any time by a keyboard interrupt signal (\c
540.SM CTRL\s0-C).
541.B strace
542will respond by detaching itself from the traced process(es)
543leaving it (them) to continue running.
544Multiple
545.B \-p
546options can be used to attach to up to 32 processes in addition to
547.I command
548(which is optional if at least one
549.B \-p
550option is given).
551.TP
552.BI "\-s " strsize
553Specify the maximum string size to print (the default is 32). Note
554that filenames are not considered strings and are always printed in
555full.
556.TP
557.BI "\-S " sortby
558Sort the output of the histogram printed by the
559.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000560option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000561.BR time ,
562.BR calls ,
563.BR name ,
564and
565.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000566(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000567.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568.TP
569.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000570Run command with the user \s-1ID\s0, group \s-2ID\s0, and
571supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572.IR username .
573This option is only useful when running as root and enables the
574correct execution of setuid and/or setgid binaries.
575Unless this option is used setuid and setgid programs are executed
576without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000577.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000578\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000579Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000580.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000581in its list of environment variables.
582.TP
583.BI "\-E " var
584Remove
585.IR var
586from the inherited list of environment variables before passing it on to
587the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000588.SH DIAGNOSTICS
589When
590.I command
591exits,
592.B strace
593exits with the same exit status.
594If
595.I command
596is terminated by a signal,
597.B strace
598terminates itself with the same signal, so that
599.B strace
600can be used as a wrapper process transparent to the invoking parent process.
601.LP
602When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000603.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000604the exit status of
605.B strace
606is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607.SH "SETUID INSTALLATION"
608If
609.B strace
610is installed setuid to root then the invoking user will be able to
611attach to and trace processes owned by any user.
612In addition setuid and setgid programs will be executed and traced
613with the correct effective privileges.
614Since only users trusted with full root privileges should be allowed
615to do these things,
616it only makes sense to install
617.B strace
618as setuid to root when the users who can execute it are restricted
619to those users who have this trust.
620For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000621.B strace
622with mode `rwsr-xr--', user
623.B root
624and group
625.BR trace ,
626where members of the
627.B trace
628group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000630a non-setuid version of
631.B strace
632for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000633.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000634.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000635.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000636.BR ptrace (2),
637.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638.SH NOTES
639It is a pity that so much tracing clutter is produced by systems
640employing shared libraries.
641.LP
642It is instructive to think about system call inputs and outputs
643as data-flow across the user/kernel boundary. Because user-space
644and kernel-space are separate and address-protected, it is
645sometimes possible to make deductive inferences about process
646behavior using inputs and outputs as propositions.
647.LP
648In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000649or have a different name. For example, on System V-derived systems
650the true
651.BR time (2)
652system call does not take an argument and the
653.B stat
654function is called
655.B xstat
656and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657discrepancies are normal but idiosyncratic characteristics of the
658system call interface and are accounted for by C library wrapper
659functions.
660.LP
661On some platforms a process that has a system call trace applied
662to it with the
663.B \-p
664option will receive a
665.BR \s-1SIGSTOP\s0 .
666This signal may interrupt a system call that is not restartable.
667This may have an unpredictable effect on the process
668if the process takes no action to restart the system call.
669.SH BUGS
670Programs that use the
671.I setuid
672bit do not have
673effective user
674.SM ID
675privileges while being traced.
676.LP
677A traced process ignores
678.SM SIGSTOP
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000679except on SVR4 platforms.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680.LP
681A traced process which tries to block SIGTRAP will be sent a SIGSTOP
682in an attempt to force continuation of tracing.
683.LP
684A traced process runs slowly.
685.LP
686Traced processes which are descended from
687.I command
688may be left running after an interrupt signal (\c
689.SM CTRL\s0-C).
690.LP
691On Linux, exciting as it would be, tracing the init process is forbidden.
692.LP
693The
694.B \-i
695option is weakly supported.
696.SH HISTORY
697.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000698The original
699.B strace
700was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000701for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000702The SunOS version of
703.B strace
704was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000705by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000706Even though Paul released
707.B strace
7082.5 in 1992,
709Branko's work was based on Paul's
710.B strace
7111.5 release from 1991.
712In 1993, Rick Sladkey merged
713.B strace
7142.5 for SunOS and the second release of
715.B strace
716for Linux, added many of the features of
717.BR truss (1)
718from SVR4, and produced an
719.B strace
720that worked on both platforms. In 1994 Rick ported
721.B strace
722to SVR4 and Solaris and wrote the
723automatic configuration support. In 1995 he ported
724.B strace
725to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000726and tired of writing about himself in the third person.
Roland McGrath98a3ecf2008-08-28 23:41:57 +0000727.SH BUGS
728The SIGTRAP signal is used internally by the kernel implementation of
729system call tracing. When a traced process receives a SIGTRAP signal not
730associated with tracing, strace will not report that signal correctly.
731This signal is not normally used by programs, but could be via a hard-coded
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000732break instruction or via
733.BR kill (2).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000734.SH PROBLEMS
735Problems with
736.B strace
Roland McGrath4a9b49a2003-01-14 23:40:55 +0000737should be reported via the Debian Bug Tracking System,
738or to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000739.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000740mailing list at <strace\-devel@lists.sourceforge.net>.