blob: a98b9f99676d11f8d54cd6e4293c9885e14d25d7 [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[
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +000046.B \-CdffhiqrtttTvxx
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[
87.BI \-e expr
88]
89\&...
90[
91.BI \-O overhead
92]
93[
94.BI \-S sortby
95]
96[
97.I command
98[
99.I arg
100\&...
101]
102]
103.SH DESCRIPTION
104.IX "strace command" "" "\fLstrace\fR command"
105.LP
106In the simplest case
107.B strace
108runs the specified
109.I command
110until it exits.
111It intercepts and records the system calls which are called
112by a process and the signals which are received by a process.
113The name of each system call, its arguments and its return value
114are printed on standard error or to the file specified with the
115.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +0000116option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000117.LP
118.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000119is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +0000120System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121it invaluable for solving problems with
122programs for which the source is not readily available since
123they do not need to be recompiled in order to trace them.
124Students, hackers and the overly-curious will find that
125a great deal can be learned about a system and its system calls by
126tracing even ordinary programs. And programmers will find that
127since system calls and signals are events that happen at the user/kernel
128interface, a close examination of this boundary is very
129useful for bug isolation, sanity checking and
130attempting to capture race conditions.
131.LP
132Each line in the trace contains the system call name, followed
133by its arguments in parentheses and its return value.
134An example from stracing the command ``cat /dev/null'' is:
135.CW
136open("/dev/null", O_RDONLY) = 3
137.CE
138Errors (typically a return value of \-1) have the errno symbol
139and error string appended.
140.CW
141open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
142.CE
143Signals are printed as a signal symbol and a signal string.
144An excerpt from stracing and interrupting the command ``sleep 666'' is:
145.CW
146sigsuspend([] <unfinished ...>
147--- SIGINT (Interrupt) ---
148+++ killed by SIGINT +++
149.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000150If a system call is being executed and meanwhile another one is being called
151from a different thread/process then
152.B strace
153will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000154being
155.IR unfinished .
156When the call returns it will be marked as
157.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000158.CW
159[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
160[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
161[pid 28772] <... select resumed> ) = 1 (in [3])
162.CE
163Interruption of a (restartable) system call by a signal delivery is processed
164differently as kernel terminates the system call and also arranges its
165immediate reexecution after the signal handler completes.
166.CW
167read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
168--- SIGALRM (Alarm clock) @ 0 (0) ---
169rt_sigreturn(0xe) = 0
170read(0, ""..., 1) = 0
171.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172Arguments are printed in symbolic form with a passion.
Roland McGrath0411b402003-10-22 06:16:32 +0000173This example shows the shell performing ``>>xyzzy'' output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174.CW
175open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
176.CE
177Here the three argument form of open is decoded by breaking down the
178flag argument into its three bitwise-OR constituents and printing the
179mode value in octal by tradition. Where traditional or native
180usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000181In some cases,
182.B strace
183output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184.LP
185Structure pointers are dereferenced and the members are displayed
186as appropriate. In all cases arguments are formatted in the most C-like
187fashion possible.
188For example, the essence of the command ``ls \-l /dev/null'' is captured as:
189.CW
190lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
191.CE
192Notice how the `struct stat' argument is dereferenced and how each member is
193displayed symbolically. In particular, observe how the st_mode member
194is carefully decoded into a bitwise-OR of symbolic and numeric values.
195Also notice in this example that the first argument to lstat is an input
196to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000197arguments are not modified if the system call fails, arguments may not
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198always be dereferenced. For example, retrying the ``ls \-l'' example
199with a non-existent file produces the following line:
200.CW
201lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
202.CE
203In this case the porch light is on but nobody is home.
204.LP
205Character pointers are dereferenced and printed as C strings.
206Non-printing characters in strings are normally represented by
207ordinary C escape codes.
208Only the first
209.I strsize
210(32 by default) bytes of strings are printed;
211longer strings have an ellipsis appended following the closing quote.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000212Here is a line from ``ls \-l'' where the
213.B getpwuid
214library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215.CW
216read(3, "root::0:0:System Administrator:/"..., 1024) = 422
217.CE
218While structures are annotated using curly braces, simple pointers
219and arrays are printed using square brackets with commas separating
220elements. Here is an example from the command ``id'' on a system with
221supplementary group ids:
222.CW
223getgroups(32, [100, 0]) = 2
224.CE
225On the other hand, bit-sets are also shown using square brackets
226but set elements are separated only by a space. Here is the shell
227preparing to execute an external command:
228.CW
229sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
230.CE
231Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
232In some cases the bit-set is so full that printing out the unset
233elements is more valuable. In that case, the bit-set is prefixed by
234a tilde like this:
235.CW
236sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
237.CE
238Here the second argument represents the full set of all signals.
239.SH OPTIONS
240.TP 12
241.TP
242.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000243Count time, calls, and errors for each system call and report a summary on
244program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000245running in the kernel) independent of wall clock time. If
246.B \-c
247is used with
248.B \-f
249or
250.B \-F
251(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000253.B \-C
254Like
255.B \-c
256but also print regular output while processes are running.
257.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000259Show some debugging output of
260.B strace
261itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262.TP
263.B \-f
264Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000265processes as a result of the
266.BR fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000267system call.
268.IP
269On non-Linux platforms the new process is
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270attached to as soon as its pid is known (through the return value of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000271.BR fork (2)
272in the parent process). This means that such children may run
273uncontrolled for a while (especially in the case of a
274.BR vfork (2)),
275until the parent is scheduled again to complete its
276.RB ( v ) fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000277call. On Linux the child is traced from its first instruction with no delay.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000278If the parent process decides to
279.BR wait (2)
280for a child that is currently
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281being traced, it is suspended until an appropriate child process either
282terminates or incurs a signal that would cause it to terminate (as
283determined from the child's current signal disposition).
Roland McGrath41c48222008-07-18 00:25:10 +0000284.IP
285On SunOS 4.x the tracing of
286.BR vfork s
287is accomplished with some dynamic linking trickery.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288.TP
289.B \-ff
290If the
291.B \-o
292.I filename
293option is in effect, each processes trace is written to
294.I filename.pid
295where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000296This is incompatible with
297.BR \-c ,
298since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299.TP
300.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000301This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000302.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303.TP
304.B \-h
305Print the help summary.
306.TP
307.B \-i
308Print the instruction pointer at the time of the system call.
309.TP
310.B \-q
311Suppress messages about attaching, detaching etc. This happens
312automatically when output is redirected to a file and the command
313is run directly instead of attaching.
314.TP
315.B \-r
316Print a relative timestamp upon entry to each system call. This
317records the time difference between the beginning of successive
318system calls.
319.TP
320.B \-t
321Prefix each line of the trace with the time of day.
322.TP
323.B \-tt
324If given twice, the time printed will include the microseconds.
325.TP
326.B \-ttt
327If given thrice, the time printed will include the microseconds
328and the leading portion will be printed as the number
329of seconds since the epoch.
330.TP
331.B \-T
332Show the time spent in system calls. This records the time
333difference between the beginning and the end of each system call.
334.TP
335.B \-v
336Print unabbreviated versions of environment, stat, termios, etc.
337calls. These structures are very common in calls and so the default
338behavior displays a reasonable subset of structure members. Use
339this option to get all of the gory details.
340.TP
341.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000342Print the version number of
343.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344.TP
345.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000346Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000347.TP
348.B \-xx
349Print all strings in hexadecimal string format.
350.TP
351.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000352Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353.TP
354.BI "\-e " expr
355A qualifying expression which modifies which events to trace
356or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000357.RS 15
358.IP
359[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
360.RE
361.IP
362where
363.I qualifier
364is one of
365.BR trace ,
366.BR abbrev ,
367.BR verbose ,
368.BR raw ,
369.BR signal ,
370.BR read ,
371or
372.B write
373and
374.I value
375is a qualifier-dependent symbol or number. The default
376qualifier is
377.BR trace .
378Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000379.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000380means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000381.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000382which in turn means trace only the
383.B open
384system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000385.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000386means to trace every system call except
387.BR open .
388In addition, the special values
389.B all
390and
391.B none
392have the obvious meanings.
393.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000395expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396the exclamation point with a backslash.
397.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000398\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399Trace only the specified set of system calls. The
400.B \-c
401option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000402to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000403.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000404means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405trace those four system calls. Be careful when making inferences
406about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000407are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000408.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000410\fB\-e\ trace\fR=\fIfile\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411Trace all system calls which take a file name as an argument. You
412can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000413.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414which is useful to seeing what files the process is referencing.
415Furthermore, using the abbreviation will ensure that you don't
416accidentally forget to include a call like
417.B lstat
418in the list. Betchya woulda forgot that one.
419.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000420\fB\-e\ trace\fR=\fIprocess\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421Trace all system calls which involve process management. This
422is useful for watching the fork, wait, and exec steps of a process.
423.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000424\fB\-e\ trace\fR=\fInetwork\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425Trace all the network related system calls.
426.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000427\fB\-e\ trace\fR=\fIsignal\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428Trace all signal related system calls.
429.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000430\fB\-e\ trace\fR=\fIipc\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431Trace all IPC related system calls.
432.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000433\fB\-e\ trace\fR=\fIdesc\fR
Roland McGrath2fe7b132005-07-05 03:25:35 +0000434Trace all file descriptor related system calls.
435.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000436\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000438The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000439.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000440The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000442option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000443.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000445\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000447default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000448.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000450\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000451Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452This option has the effect of causing all arguments to be printed
453in hexadecimal. This is mostly useful if you don't trust the
454decoding or you need to know the actual numeric value of an
455argument.
456.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000457\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000458Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000459.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000460For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000461.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000462(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000463.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000464causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000466\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000467Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000468file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000469all input activity on file descriptors
470.I 3
471and
472.I 5
473use
474\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000475Note that this is independent from the normal tracing of the
476.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000477system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000478.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000480\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000481Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000483all output activity on file descriptors
484.I 3
485and
486.I 5
487use
488\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000489Note that this is independent from the normal tracing of the
490.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000492.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493.TP
494.BI "\-o " filename
495Write the trace output to the file
496.I filename
497rather than to stderr.
498Use
499.I filename.pid
500if
501.B \-ff
502is used.
503If the argument begins with `|' or with `!' then the rest of the
504argument is treated as a command and all output is piped to it.
505This is convenient for piping the debugging output to a program
506without affecting the redirections of executed programs.
507.TP
508.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000509Set the overhead for tracing system calls to
510.I overhead
511microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512This is useful for overriding the default heuristic for guessing
513how much time is spent in mere measuring when timing system calls using
514the
515.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000516option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000517program run without tracing (using
518.BR time (1))
519and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000521.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522.TP
523.BI "\-p " pid
524Attach to the process with the process
525.SM ID
526.I pid
527and begin tracing.
528The trace may be terminated
529at any time by a keyboard interrupt signal (\c
530.SM CTRL\s0-C).
531.B strace
532will respond by detaching itself from the traced process(es)
533leaving it (them) to continue running.
534Multiple
535.B \-p
536options can be used to attach to up to 32 processes in addition to
537.I command
538(which is optional if at least one
539.B \-p
540option is given).
541.TP
542.BI "\-s " strsize
543Specify the maximum string size to print (the default is 32). Note
544that filenames are not considered strings and are always printed in
545full.
546.TP
547.BI "\-S " sortby
548Sort the output of the histogram printed by the
549.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000550option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000551.BR time ,
552.BR calls ,
553.BR name ,
554and
555.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000556(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000557.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558.TP
559.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000560Run command with the user \s-1ID\s0, group \s-2ID\s0, and
561supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562.IR username .
563This option is only useful when running as root and enables the
564correct execution of setuid and/or setgid binaries.
565Unless this option is used setuid and setgid programs are executed
566without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000567.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000568\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000569Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000570.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000571in its list of environment variables.
572.TP
573.BI "\-E " var
574Remove
575.IR var
576from the inherited list of environment variables before passing it on to
577the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000578.SH DIAGNOSTICS
579When
580.I command
581exits,
582.B strace
583exits with the same exit status.
584If
585.I command
586is terminated by a signal,
587.B strace
588terminates itself with the same signal, so that
589.B strace
590can be used as a wrapper process transparent to the invoking parent process.
591.LP
592When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000593.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000594the exit status of
595.B strace
596is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597.SH "SETUID INSTALLATION"
598If
599.B strace
600is installed setuid to root then the invoking user will be able to
601attach to and trace processes owned by any user.
602In addition setuid and setgid programs will be executed and traced
603with the correct effective privileges.
604Since only users trusted with full root privileges should be allowed
605to do these things,
606it only makes sense to install
607.B strace
608as setuid to root when the users who can execute it are restricted
609to those users who have this trust.
610For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000611.B strace
612with mode `rwsr-xr--', user
613.B root
614and group
615.BR trace ,
616where members of the
617.B trace
618group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000620a non-setuid version of
621.B strace
622for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000624.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000625.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000626.BR ptrace (2),
627.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000628.SH NOTES
629It is a pity that so much tracing clutter is produced by systems
630employing shared libraries.
631.LP
632It is instructive to think about system call inputs and outputs
633as data-flow across the user/kernel boundary. Because user-space
634and kernel-space are separate and address-protected, it is
635sometimes possible to make deductive inferences about process
636behavior using inputs and outputs as propositions.
637.LP
638In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000639or have a different name. For example, on System V-derived systems
640the true
641.BR time (2)
642system call does not take an argument and the
643.B stat
644function is called
645.B xstat
646and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647discrepancies are normal but idiosyncratic characteristics of the
648system call interface and are accounted for by C library wrapper
649functions.
650.LP
651On some platforms a process that has a system call trace applied
652to it with the
653.B \-p
654option will receive a
655.BR \s-1SIGSTOP\s0 .
656This signal may interrupt a system call that is not restartable.
657This may have an unpredictable effect on the process
658if the process takes no action to restart the system call.
659.SH BUGS
660Programs that use the
661.I setuid
662bit do not have
663effective user
664.SM ID
665privileges while being traced.
666.LP
667A traced process ignores
668.SM SIGSTOP
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000669except on SVR4 platforms.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670.LP
671A traced process which tries to block SIGTRAP will be sent a SIGSTOP
672in an attempt to force continuation of tracing.
673.LP
674A traced process runs slowly.
675.LP
676Traced processes which are descended from
677.I command
678may be left running after an interrupt signal (\c
679.SM CTRL\s0-C).
680.LP
681On Linux, exciting as it would be, tracing the init process is forbidden.
682.LP
683The
684.B \-i
685option is weakly supported.
686.SH HISTORY
687.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000688The original
689.B strace
690was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000691for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000692The SunOS version of
693.B strace
694was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000696Even though Paul released
697.B strace
6982.5 in 1992,
699Branko's work was based on Paul's
700.B strace
7011.5 release from 1991.
702In 1993, Rick Sladkey merged
703.B strace
7042.5 for SunOS and the second release of
705.B strace
706for Linux, added many of the features of
707.BR truss (1)
708from SVR4, and produced an
709.B strace
710that worked on both platforms. In 1994 Rick ported
711.B strace
712to SVR4 and Solaris and wrote the
713automatic configuration support. In 1995 he ported
714.B strace
715to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716and tired of writing about himself in the third person.
Roland McGrath98a3ecf2008-08-28 23:41:57 +0000717.SH BUGS
718The SIGTRAP signal is used internally by the kernel implementation of
719system call tracing. When a traced process receives a SIGTRAP signal not
720associated with tracing, strace will not report that signal correctly.
721This signal is not normally used by programs, but could be via a hard-coded
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000722break instruction or via
723.BR kill (2).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000724.SH PROBLEMS
725Problems with
726.B strace
Roland McGrath4a9b49a2003-01-14 23:40:55 +0000727should be reported via the Debian Bug Tracking System,
728or to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000729.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000730mailing list at <strace\-devel@lists.sourceforge.net>.