blob: f31b2172ae19531b3fe73fb498879cc332160e65 [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
Namhyung Kim96792962012-10-24 11:41:57 +0900398.BR "\-e\ trace" = memory
399Trace all memory mapping related system calls.
400.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000401\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000403The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000404.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000405The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000407option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000408.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000410\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000412default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000413.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000415\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000416Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417This option has the effect of causing all arguments to be printed
418in hexadecimal. This is mostly useful if you don't trust the
419decoding or you need to know the actual numeric value of an
420argument.
421.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000422\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000423Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000424.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000425For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000426.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000427(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000428.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000429causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000431\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000432Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000434all input activity on file descriptors
435.I 3
436and
437.I 5
438use
439\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000440Note that this is independent from the normal tracing of the
441.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000443.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000445\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000446Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000448all output activity on file descriptors
449.I 3
450and
451.I 5
452use
453\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000454Note that this is independent from the normal tracing of the
455.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000456system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000457.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458.TP
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +0200459.BI "\-I " interruptible
460When strace can be interrupted by signals (such as pressing ^C).
4611: no signals are blocked; 2: fatal signals are blocked while decoding syscall
462(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
4634: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
464strace -o FILE PROG not stop on ^Z).
465.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466.BI "\-o " filename
467Write the trace output to the file
468.I filename
469rather than to stderr.
470Use
471.I filename.pid
472if
473.B \-ff
474is used.
475If the argument begins with `|' or with `!' then the rest of the
476argument is treated as a command and all output is piped to it.
477This is convenient for piping the debugging output to a program
478without affecting the redirections of executed programs.
479.TP
480.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000481Set the overhead for tracing system calls to
482.I overhead
483microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484This is useful for overriding the default heuristic for guessing
485how much time is spent in mere measuring when timing system calls using
486the
487.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000488option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000489program run without tracing (using
490.BR time (1))
491and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000493.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494.TP
495.BI "\-p " pid
496Attach to the process with the process
497.SM ID
498.I pid
499and begin tracing.
500The trace may be terminated
501at any time by a keyboard interrupt signal (\c
502.SM CTRL\s0-C).
503.B strace
504will respond by detaching itself from the traced process(es)
505leaving it (them) to continue running.
506Multiple
507.B \-p
Denys Vlasenko94f00e62012-03-26 13:31:11 +0200508options can be used to attach to many processes.
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100509-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000511.BI "\-P " path
512Trace only system calls accessing
513.I path.
514Multiple
515.B \-P
516options can be used to specify up to 256 paths.
517.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518.BI "\-s " strsize
519Specify the maximum string size to print (the default is 32). Note
520that filenames are not considered strings and are always printed in
521full.
522.TP
523.BI "\-S " sortby
524Sort the output of the histogram printed by the
525.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000526option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000527.BR time ,
528.BR calls ,
529.BR name ,
530and
531.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000532(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000533.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000534.TP
535.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000536Run command with the user \s-1ID\s0, group \s-2ID\s0, and
537supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538.IR username .
539This option is only useful when running as root and enables the
540correct execution of setuid and/or setgid binaries.
541Unless this option is used setuid and setgid programs are executed
542without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000543.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000544\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000545Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000546.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000547in its list of environment variables.
548.TP
549.BI "\-E " var
550Remove
551.IR var
552from the inherited list of environment variables before passing it on to
553the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000554.SH DIAGNOSTICS
555When
556.I command
557exits,
558.B strace
559exits with the same exit status.
560If
561.I command
562is terminated by a signal,
563.B strace
564terminates itself with the same signal, so that
565.B strace
566can be used as a wrapper process transparent to the invoking parent process.
567.LP
568When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000569.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000570the exit status of
571.B strace
572is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573.SH "SETUID INSTALLATION"
574If
575.B strace
576is installed setuid to root then the invoking user will be able to
577attach to and trace processes owned by any user.
578In addition setuid and setgid programs will be executed and traced
579with the correct effective privileges.
580Since only users trusted with full root privileges should be allowed
581to do these things,
582it only makes sense to install
583.B strace
584as setuid to root when the users who can execute it are restricted
585to those users who have this trust.
586For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000587.B strace
588with mode `rwsr-xr--', user
589.B root
590and group
591.BR trace ,
592where members of the
593.B trace
594group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000596a non-setuid version of
597.B strace
598for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000600.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000601.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000602.BR ptrace (2),
603.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604.SH NOTES
605It is a pity that so much tracing clutter is produced by systems
606employing shared libraries.
607.LP
608It is instructive to think about system call inputs and outputs
609as data-flow across the user/kernel boundary. Because user-space
610and kernel-space are separate and address-protected, it is
611sometimes possible to make deductive inferences about process
612behavior using inputs and outputs as propositions.
613.LP
614In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000615or have a different name. For example, on System V-derived systems
616the true
617.BR time (2)
618system call does not take an argument and the
619.B stat
620function is called
621.B xstat
622and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000623discrepancies are normal but idiosyncratic characteristics of the
624system call interface and are accounted for by C library wrapper
625functions.
626.LP
627On some platforms a process that has a system call trace applied
628to it with the
629.B \-p
630option will receive a
631.BR \s-1SIGSTOP\s0 .
632This signal may interrupt a system call that is not restartable.
633This may have an unpredictable effect on the process
634if the process takes no action to restart the system call.
635.SH BUGS
636Programs that use the
637.I setuid
638bit do not have
639effective user
640.SM ID
641privileges while being traced.
642.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000643A traced process runs slowly.
644.LP
645Traced processes which are descended from
646.I command
647may be left running after an interrupt signal (\c
648.SM CTRL\s0-C).
649.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650The
651.B \-i
652option is weakly supported.
653.SH HISTORY
654.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000655The original
656.B strace
657was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000659The SunOS version of
660.B strace
661was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000663Even though Paul released
664.B strace
6652.5 in 1992,
666Branko's work was based on Paul's
667.B strace
6681.5 release from 1991.
669In 1993, Rick Sladkey merged
670.B strace
6712.5 for SunOS and the second release of
672.B strace
673for Linux, added many of the features of
674.BR truss (1)
675from SVR4, and produced an
676.B strace
677that worked on both platforms. In 1994 Rick ported
678.B strace
679to SVR4 and Solaris and wrote the
680automatic configuration support. In 1995 he ported
681.B strace
682to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000683and tired of writing about himself in the third person.
684.SH PROBLEMS
685Problems with
686.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100687should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000688.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000689mailing list at <strace\-devel@lists.sourceforge.net>.