blob: faf4d45c1d1c55e10f8a845d16cc8dafa1ce2b95 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000027.de CW
28.sp
29.nf
30.ft CW
31..
32.de CE
Wichert Akkerman8829a551999-06-11 13:18:40 +000033.ft R
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034.fi
35.sp
36..
Dmitry V. Levina7835e62010-03-31 17:26:49 +000037.TH STRACE 1 "2010-03-30"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038.SH NAME
39strace \- trace system calls and signals
40.SH SYNOPSIS
41.B strace
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020042[\fB-CdffhiqrtttTvVxxy\fR]
43[\fB-I\fIn\fR]
44[\fB-e\fIexpr\fR]... [\fB-a\fIcolumn\fR]
45[\fB-o\fIfile\fR]
46[\fB-s\fIstrsize\fR]
47[\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
48[\fB-D\fR]
49[\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
50\fIcommand\fR [\fIargs\fR]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051.sp
52.B strace
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020053\fB-c\fR[\fBdf\fR]
54[\fB-I\fIn\fR]
55[\fB-e\fIexpr\fR]... [\fB-O\fIoverhead\fR]
56[\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
57[\fB-D\fR]
58[\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
59\fIcommand\fR [\fIargs\fR]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060.SH DESCRIPTION
61.IX "strace command" "" "\fLstrace\fR command"
62.LP
63In the simplest case
64.B strace
65runs the specified
66.I command
67until it exits.
68It intercepts and records the system calls which are called
69by a process and the signals which are received by a process.
70The name of each system call, its arguments and its return value
71are printed on standard error or to the file specified with the
72.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +000073option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074.LP
75.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +000076is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +000077System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078it invaluable for solving problems with
79programs for which the source is not readily available since
80they do not need to be recompiled in order to trace them.
81Students, hackers and the overly-curious will find that
82a great deal can be learned about a system and its system calls by
83tracing even ordinary programs. And programmers will find that
84since system calls and signals are events that happen at the user/kernel
85interface, a close examination of this boundary is very
86useful for bug isolation, sanity checking and
87attempting to capture race conditions.
88.LP
89Each line in the trace contains the system call name, followed
90by its arguments in parentheses and its return value.
91An example from stracing the command ``cat /dev/null'' is:
92.CW
93open("/dev/null", O_RDONLY) = 3
94.CE
95Errors (typically a return value of \-1) have the errno symbol
96and error string appended.
97.CW
98open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
99.CE
100Signals are printed as a signal symbol and a signal string.
101An excerpt from stracing and interrupting the command ``sleep 666'' is:
102.CW
103sigsuspend([] <unfinished ...>
104--- SIGINT (Interrupt) ---
105+++ killed by SIGINT +++
106.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000107If a system call is being executed and meanwhile another one is being called
108from a different thread/process then
109.B strace
110will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000111being
112.IR unfinished .
113When the call returns it will be marked as
114.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000115.CW
116[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
117[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
118[pid 28772] <... select resumed> ) = 1 (in [3])
119.CE
120Interruption of a (restartable) system call by a signal delivery is processed
121differently as kernel terminates the system call and also arranges its
122immediate reexecution after the signal handler completes.
123.CW
124read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
125--- SIGALRM (Alarm clock) @ 0 (0) ---
126rt_sigreturn(0xe) = 0
127read(0, ""..., 1) = 0
128.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000129Arguments are printed in symbolic form with a passion.
Roland McGrath0411b402003-10-22 06:16:32 +0000130This example shows the shell performing ``>>xyzzy'' output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131.CW
132open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
133.CE
Dmitry V. Levin9b3eb842012-02-22 00:29:44 +0000134Here the third argument of open is decoded by breaking down the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135flag argument into its three bitwise-OR constituents and printing the
136mode value in octal by tradition. Where traditional or native
137usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000138In some cases,
139.B strace
140output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000141.LP
142Structure pointers are dereferenced and the members are displayed
143as appropriate. In all cases arguments are formatted in the most C-like
144fashion possible.
145For example, the essence of the command ``ls \-l /dev/null'' is captured as:
146.CW
147lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
148.CE
149Notice how the `struct stat' argument is dereferenced and how each member is
150displayed symbolically. In particular, observe how the st_mode member
151is carefully decoded into a bitwise-OR of symbolic and numeric values.
152Also notice in this example that the first argument to lstat is an input
153to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000154arguments are not modified if the system call fails, arguments may not
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155always be dereferenced. For example, retrying the ``ls \-l'' example
156with a non-existent file produces the following line:
157.CW
158lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
159.CE
160In this case the porch light is on but nobody is home.
161.LP
162Character pointers are dereferenced and printed as C strings.
163Non-printing characters in strings are normally represented by
164ordinary C escape codes.
165Only the first
166.I strsize
167(32 by default) bytes of strings are printed;
168longer strings have an ellipsis appended following the closing quote.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000169Here is a line from ``ls \-l'' where the
170.B getpwuid
171library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172.CW
173read(3, "root::0:0:System Administrator:/"..., 1024) = 422
174.CE
175While structures are annotated using curly braces, simple pointers
176and arrays are printed using square brackets with commas separating
177elements. Here is an example from the command ``id'' on a system with
178supplementary group ids:
179.CW
180getgroups(32, [100, 0]) = 2
181.CE
182On the other hand, bit-sets are also shown using square brackets
183but set elements are separated only by a space. Here is the shell
184preparing to execute an external command:
185.CW
186sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
187.CE
188Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
189In some cases the bit-set is so full that printing out the unset
190elements is more valuable. In that case, the bit-set is prefixed by
191a tilde like this:
192.CW
193sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
194.CE
195Here the second argument represents the full set of all signals.
196.SH OPTIONS
197.TP 12
198.TP
199.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000200Count time, calls, and errors for each system call and report a summary on
201program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000202running in the kernel) independent of wall clock time. If
203.B \-c
204is used with
205.B \-f
206or
207.B \-F
208(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000209.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000210.B \-C
211Like
212.B \-c
213but also print regular output while processes are running.
214.TP
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200215.B \-D
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200216Run tracer process as a detached grandchild, not as parent of the
217tracee. This reduces the visible effect of
218.B strace
219by keeping the tracee a direct child of the calling process.
220.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000221.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000222Show some debugging output of
223.B strace
224itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225.TP
226.B \-f
227Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000228processes as a result of the
229.BR fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000230system call.
231.IP
232On non-Linux platforms the new process is
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233attached to as soon as its pid is known (through the return value of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000234.BR fork (2)
235in the parent process). This means that such children may run
236uncontrolled for a while (especially in the case of a
237.BR vfork (2)),
238until the parent is scheduled again to complete its
239.RB ( v ) fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000240call. On Linux the child is traced from its first instruction with no delay.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000241If the parent process decides to
242.BR wait (2)
243for a child that is currently
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244being traced, it is suspended until an appropriate child process either
245terminates or incurs a signal that would cause it to terminate (as
246determined from the child's current signal disposition).
247.TP
248.B \-ff
249If the
250.B \-o
251.I filename
252option is in effect, each processes trace is written to
253.I filename.pid
254where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000255This is incompatible with
256.BR \-c ,
257since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258.TP
259.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000260This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000261.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000262.TP
263.B \-h
264Print the help summary.
265.TP
266.B \-i
267Print the instruction pointer at the time of the system call.
268.TP
269.B \-q
270Suppress messages about attaching, detaching etc. This happens
271automatically when output is redirected to a file and the command
272is run directly instead of attaching.
273.TP
274.B \-r
275Print a relative timestamp upon entry to each system call. This
276records the time difference between the beginning of successive
277system calls.
278.TP
279.B \-t
280Prefix each line of the trace with the time of day.
281.TP
282.B \-tt
283If given twice, the time printed will include the microseconds.
284.TP
285.B \-ttt
286If given thrice, the time printed will include the microseconds
287and the leading portion will be printed as the number
288of seconds since the epoch.
289.TP
290.B \-T
291Show the time spent in system calls. This records the time
292difference between the beginning and the end of each system call.
293.TP
294.B \-v
295Print unabbreviated versions of environment, stat, termios, etc.
296calls. These structures are very common in calls and so the default
297behavior displays a reasonable subset of structure members. Use
298this option to get all of the gory details.
299.TP
300.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000301Print the version number of
302.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303.TP
304.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000305Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306.TP
307.B \-xx
308Print all strings in hexadecimal string format.
309.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000310.B \-y
311Print paths associated with file descriptor arguments.
312.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000314Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315.TP
316.BI "\-e " expr
317A qualifying expression which modifies which events to trace
318or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000319.RS 15
320.IP
321[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
322.RE
323.IP
324where
325.I qualifier
326is one of
327.BR trace ,
328.BR abbrev ,
329.BR verbose ,
330.BR raw ,
331.BR signal ,
332.BR read ,
333or
334.B write
335and
336.I value
337is a qualifier-dependent symbol or number. The default
338qualifier is
339.BR trace .
340Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000341.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000342means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000343.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000344which in turn means trace only the
345.B open
346system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000347.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000348means to trace every system call except
349.BR open .
350In addition, the special values
351.B all
352and
353.B none
354have the obvious meanings.
355.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000357expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358the exclamation point with a backslash.
359.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000360\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000361Trace only the specified set of system calls. The
362.B \-c
363option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000364to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000365.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000366means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367trace those four system calls. Be careful when making inferences
368about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000369are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000370.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000372.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373Trace all system calls which take a file name as an argument. You
374can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000375.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376which is useful to seeing what files the process is referencing.
377Furthermore, using the abbreviation will ensure that you don't
378accidentally forget to include a call like
379.B lstat
380in the list. Betchya woulda forgot that one.
381.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000382.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383Trace all system calls which involve process management. This
384is useful for watching the fork, wait, and exec steps of a process.
385.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000386.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387Trace all the network related system calls.
388.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000389.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390Trace all signal related system calls.
391.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000392.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393Trace all IPC related system calls.
394.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000395.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000396Trace all file descriptor related system calls.
397.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000398\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000400The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000401.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000402The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000404option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000405.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000407\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000409default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000410.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000412\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000413Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414This option has the effect of causing all arguments to be printed
415in hexadecimal. This is mostly useful if you don't trust the
416decoding or you need to know the actual numeric value of an
417argument.
418.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000419\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000420Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000421.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000422For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000423.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000424(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000425.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000426causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000428\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000429Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000431all input activity on file descriptors
432.I 3
433and
434.I 5
435use
436\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000437Note that this is independent from the normal tracing of the
438.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000440.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000442\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000443Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000445all output activity on file descriptors
446.I 3
447and
448.I 5
449use
450\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000451Note that this is independent from the normal tracing of the
452.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000454.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455.TP
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +0200456.BI "\-I " interruptible
457When strace can be interrupted by signals (such as pressing ^C).
4581: no signals are blocked; 2: fatal signals are blocked while decoding syscall
459(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
4604: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
461strace -o FILE PROG not stop on ^Z).
462.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463.BI "\-o " filename
464Write the trace output to the file
465.I filename
466rather than to stderr.
467Use
468.I filename.pid
469if
470.B \-ff
471is used.
472If the argument begins with `|' or with `!' then the rest of the
473argument is treated as a command and all output is piped to it.
474This is convenient for piping the debugging output to a program
475without affecting the redirections of executed programs.
476.TP
477.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000478Set the overhead for tracing system calls to
479.I overhead
480microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481This is useful for overriding the default heuristic for guessing
482how much time is spent in mere measuring when timing system calls using
483the
484.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000485option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000486program run without tracing (using
487.BR time (1))
488and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000490.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491.TP
492.BI "\-p " pid
493Attach to the process with the process
494.SM ID
495.I pid
496and begin tracing.
497The trace may be terminated
498at any time by a keyboard interrupt signal (\c
499.SM CTRL\s0-C).
500.B strace
501will respond by detaching itself from the traced process(es)
502leaving it (them) to continue running.
503Multiple
504.B \-p
Denys Vlasenko94f00e62012-03-26 13:31:11 +0200505options can be used to attach to many processes.
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100506-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000508.BI "\-P " path
509Trace only system calls accessing
510.I path.
511Multiple
512.B \-P
513options can be used to specify up to 256 paths.
514.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515.BI "\-s " strsize
516Specify the maximum string size to print (the default is 32). Note
517that filenames are not considered strings and are always printed in
518full.
519.TP
520.BI "\-S " sortby
521Sort the output of the histogram printed by the
522.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000523option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000524.BR time ,
525.BR calls ,
526.BR name ,
527and
528.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000529(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000530.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531.TP
532.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000533Run command with the user \s-1ID\s0, group \s-2ID\s0, and
534supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535.IR username .
536This option is only useful when running as root and enables the
537correct execution of setuid and/or setgid binaries.
538Unless this option is used setuid and setgid programs are executed
539without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000540.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000541\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000542Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000543.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000544in its list of environment variables.
545.TP
546.BI "\-E " var
547Remove
548.IR var
549from the inherited list of environment variables before passing it on to
550the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000551.SH DIAGNOSTICS
552When
553.I command
554exits,
555.B strace
556exits with the same exit status.
557If
558.I command
559is terminated by a signal,
560.B strace
561terminates itself with the same signal, so that
562.B strace
563can be used as a wrapper process transparent to the invoking parent process.
564.LP
565When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000566.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000567the exit status of
568.B strace
569is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570.SH "SETUID INSTALLATION"
571If
572.B strace
573is installed setuid to root then the invoking user will be able to
574attach to and trace processes owned by any user.
575In addition setuid and setgid programs will be executed and traced
576with the correct effective privileges.
577Since only users trusted with full root privileges should be allowed
578to do these things,
579it only makes sense to install
580.B strace
581as setuid to root when the users who can execute it are restricted
582to those users who have this trust.
583For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000584.B strace
585with mode `rwsr-xr--', user
586.B root
587and group
588.BR trace ,
589where members of the
590.B trace
591group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000593a non-setuid version of
594.B strace
595for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000597.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000598.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000599.BR ptrace (2),
600.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601.SH NOTES
602It is a pity that so much tracing clutter is produced by systems
603employing shared libraries.
604.LP
605It is instructive to think about system call inputs and outputs
606as data-flow across the user/kernel boundary. Because user-space
607and kernel-space are separate and address-protected, it is
608sometimes possible to make deductive inferences about process
609behavior using inputs and outputs as propositions.
610.LP
611In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000612or have a different name. For example, on System V-derived systems
613the true
614.BR time (2)
615system call does not take an argument and the
616.B stat
617function is called
618.B xstat
619and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620discrepancies are normal but idiosyncratic characteristics of the
621system call interface and are accounted for by C library wrapper
622functions.
623.LP
624On some platforms a process that has a system call trace applied
625to it with the
626.B \-p
627option will receive a
628.BR \s-1SIGSTOP\s0 .
629This signal may interrupt a system call that is not restartable.
630This may have an unpredictable effect on the process
631if the process takes no action to restart the system call.
632.SH BUGS
633Programs that use the
634.I setuid
635bit do not have
636effective user
637.SM ID
638privileges while being traced.
639.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000640A traced process runs slowly.
641.LP
642Traced processes which are descended from
643.I command
644may be left running after an interrupt signal (\c
645.SM CTRL\s0-C).
646.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647The
648.B \-i
649option is weakly supported.
650.SH HISTORY
651.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000652The original
653.B strace
654was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000656The SunOS version of
657.B strace
658was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000659by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000660Even though Paul released
661.B strace
6622.5 in 1992,
663Branko's work was based on Paul's
664.B strace
6651.5 release from 1991.
666In 1993, Rick Sladkey merged
667.B strace
6682.5 for SunOS and the second release of
669.B strace
670for Linux, added many of the features of
671.BR truss (1)
672from SVR4, and produced an
673.B strace
674that worked on both platforms. In 1994 Rick ported
675.B strace
676to SVR4 and Solaris and wrote the
677automatic configuration support. In 1995 he ported
678.B strace
679to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680and tired of writing about himself in the third person.
681.SH PROBLEMS
682Problems with
683.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100684should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000685.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000686mailing list at <strace\-devel@lists.sourceforge.net>.