blob: 2790414f685cbee5f7d86553b9755fc4a28a622b [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
42[
Grant Edwards8a082772011-04-07 20:25:40 +000043.B \-CdDffhiqrtttTvxxy
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044]
45[
46.BI \-a column
47]
48[
49.BI \-e expr
50]
51\&...
52[
53.BI \-o file
54]
55[
56.BI \-p pid
57]
58\&...
59[
Grant Edwards8a082772011-04-07 20:25:40 +000060.BI \-P path
61]
62\&...
63[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064.BI \-s strsize
65]
66[
67.BI \-u username
68]
69[
Roland McGrath4417fda2003-01-24 04:31:20 +000070.BI \-E var=val
71]
72\&...
73[
74.BI \-E var
75]
76\&...
77[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078.I command
79[
80.I arg
81\&...
82]
83]
84.sp
85.B strace
86.B \-c
87[
Andreas Schwabb87d30c2010-06-11 15:49:36 +020088.B \-D
89]
90[
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091.BI \-e expr
92]
93\&...
94[
95.BI \-O overhead
96]
97[
98.BI \-S sortby
99]
100[
101.I command
102[
103.I arg
104\&...
105]
106]
107.SH DESCRIPTION
108.IX "strace command" "" "\fLstrace\fR command"
109.LP
110In the simplest case
111.B strace
112runs the specified
113.I command
114until it exits.
115It intercepts and records the system calls which are called
116by a process and the signals which are received by a process.
117The name of each system call, its arguments and its return value
118are printed on standard error or to the file specified with the
119.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +0000120option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000121.LP
122.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +0000123is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +0000124System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000125it invaluable for solving problems with
126programs for which the source is not readily available since
127they do not need to be recompiled in order to trace them.
128Students, hackers and the overly-curious will find that
129a great deal can be learned about a system and its system calls by
130tracing even ordinary programs. And programmers will find that
131since system calls and signals are events that happen at the user/kernel
132interface, a close examination of this boundary is very
133useful for bug isolation, sanity checking and
134attempting to capture race conditions.
135.LP
136Each line in the trace contains the system call name, followed
137by its arguments in parentheses and its return value.
138An example from stracing the command ``cat /dev/null'' is:
139.CW
140open("/dev/null", O_RDONLY) = 3
141.CE
142Errors (typically a return value of \-1) have the errno symbol
143and error string appended.
144.CW
145open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
146.CE
147Signals are printed as a signal symbol and a signal string.
148An excerpt from stracing and interrupting the command ``sleep 666'' is:
149.CW
150sigsuspend([] <unfinished ...>
151--- SIGINT (Interrupt) ---
152+++ killed by SIGINT +++
153.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000154If a system call is being executed and meanwhile another one is being called
155from a different thread/process then
156.B strace
157will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000158being
159.IR unfinished .
160When the call returns it will be marked as
161.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000162.CW
163[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
164[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
165[pid 28772] <... select resumed> ) = 1 (in [3])
166.CE
167Interruption of a (restartable) system call by a signal delivery is processed
168differently as kernel terminates the system call and also arranges its
169immediate reexecution after the signal handler completes.
170.CW
171read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
172--- SIGALRM (Alarm clock) @ 0 (0) ---
173rt_sigreturn(0xe) = 0
174read(0, ""..., 1) = 0
175.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176Arguments are printed in symbolic form with a passion.
Roland McGrath0411b402003-10-22 06:16:32 +0000177This example shows the shell performing ``>>xyzzy'' output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178.CW
179open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
180.CE
Dmitry V. Levin9b3eb842012-02-22 00:29:44 +0000181Here the third argument of open is decoded by breaking down the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182flag argument into its three bitwise-OR constituents and printing the
183mode value in octal by tradition. Where traditional or native
184usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000185In some cases,
186.B strace
187output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188.LP
189Structure pointers are dereferenced and the members are displayed
190as appropriate. In all cases arguments are formatted in the most C-like
191fashion possible.
192For example, the essence of the command ``ls \-l /dev/null'' is captured as:
193.CW
194lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
195.CE
196Notice how the `struct stat' argument is dereferenced and how each member is
197displayed symbolically. In particular, observe how the st_mode member
198is carefully decoded into a bitwise-OR of symbolic and numeric values.
199Also notice in this example that the first argument to lstat is an input
200to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000201arguments are not modified if the system call fails, arguments may not
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202always be dereferenced. For example, retrying the ``ls \-l'' example
203with a non-existent file produces the following line:
204.CW
205lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
206.CE
207In this case the porch light is on but nobody is home.
208.LP
209Character pointers are dereferenced and printed as C strings.
210Non-printing characters in strings are normally represented by
211ordinary C escape codes.
212Only the first
213.I strsize
214(32 by default) bytes of strings are printed;
215longer strings have an ellipsis appended following the closing quote.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000216Here is a line from ``ls \-l'' where the
217.B getpwuid
218library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219.CW
220read(3, "root::0:0:System Administrator:/"..., 1024) = 422
221.CE
222While structures are annotated using curly braces, simple pointers
223and arrays are printed using square brackets with commas separating
224elements. Here is an example from the command ``id'' on a system with
225supplementary group ids:
226.CW
227getgroups(32, [100, 0]) = 2
228.CE
229On the other hand, bit-sets are also shown using square brackets
230but set elements are separated only by a space. Here is the shell
231preparing to execute an external command:
232.CW
233sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
234.CE
235Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
236In some cases the bit-set is so full that printing out the unset
237elements is more valuable. In that case, the bit-set is prefixed by
238a tilde like this:
239.CW
240sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
241.CE
242Here the second argument represents the full set of all signals.
243.SH OPTIONS
244.TP 12
245.TP
246.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000247Count time, calls, and errors for each system call and report a summary on
248program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000249running in the kernel) independent of wall clock time. If
250.B \-c
251is used with
252.B \-f
253or
254.B \-F
255(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000256.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000257.B \-C
258Like
259.B \-c
260but also print regular output while processes are running.
261.TP
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200262.B \-D
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200263Run tracer process as a detached grandchild, not as parent of the
264tracee. This reduces the visible effect of
265.B strace
266by keeping the tracee a direct child of the calling process.
267.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000268.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000269Show some debugging output of
270.B strace
271itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272.TP
273.B \-f
274Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000275processes as a result of the
276.BR fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000277system call.
278.IP
279On non-Linux platforms the new process is
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280attached to as soon as its pid is known (through the return value of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000281.BR fork (2)
282in the parent process). This means that such children may run
283uncontrolled for a while (especially in the case of a
284.BR vfork (2)),
285until the parent is scheduled again to complete its
286.RB ( v ) fork (2)
Roland McGrath41c48222008-07-18 00:25:10 +0000287call. On Linux the child is traced from its first instruction with no delay.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000288If the parent process decides to
289.BR wait (2)
290for a child that is currently
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291being traced, it is suspended until an appropriate child process either
292terminates or incurs a signal that would cause it to terminate (as
293determined from the child's current signal disposition).
294.TP
295.B \-ff
296If the
297.B \-o
298.I filename
299option is in effect, each processes trace is written to
300.I filename.pid
301where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000302This is incompatible with
303.BR \-c ,
304since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305.TP
306.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000307This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000308.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309.TP
310.B \-h
311Print the help summary.
312.TP
313.B \-i
314Print the instruction pointer at the time of the system call.
315.TP
316.B \-q
317Suppress messages about attaching, detaching etc. This happens
318automatically when output is redirected to a file and the command
319is run directly instead of attaching.
320.TP
321.B \-r
322Print a relative timestamp upon entry to each system call. This
323records the time difference between the beginning of successive
324system calls.
325.TP
326.B \-t
327Prefix each line of the trace with the time of day.
328.TP
329.B \-tt
330If given twice, the time printed will include the microseconds.
331.TP
332.B \-ttt
333If given thrice, the time printed will include the microseconds
334and the leading portion will be printed as the number
335of seconds since the epoch.
336.TP
337.B \-T
338Show the time spent in system calls. This records the time
339difference between the beginning and the end of each system call.
340.TP
341.B \-v
342Print unabbreviated versions of environment, stat, termios, etc.
343calls. These structures are very common in calls and so the default
344behavior displays a reasonable subset of structure members. Use
345this option to get all of the gory details.
346.TP
347.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000348Print the version number of
349.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000350.TP
351.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000352Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353.TP
354.B \-xx
355Print all strings in hexadecimal string format.
356.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000357.B \-y
358Print paths associated with file descriptor arguments.
359.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000361Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362.TP
363.BI "\-e " expr
364A qualifying expression which modifies which events to trace
365or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000366.RS 15
367.IP
368[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
369.RE
370.IP
371where
372.I qualifier
373is one of
374.BR trace ,
375.BR abbrev ,
376.BR verbose ,
377.BR raw ,
378.BR signal ,
379.BR read ,
380or
381.B write
382and
383.I value
384is a qualifier-dependent symbol or number. The default
385qualifier is
386.BR trace .
387Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000388.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000389means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000390.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000391which in turn means trace only the
392.B open
393system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000394.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000395means to trace every system call except
396.BR open .
397In addition, the special values
398.B all
399and
400.B none
401have the obvious meanings.
402.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000404expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405the exclamation point with a backslash.
406.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000407\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408Trace only the specified set of system calls. The
409.B \-c
410option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000411to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000412.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000413means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414trace those four system calls. Be careful when making inferences
415about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000416are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000417.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000419.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420Trace all system calls which take a file name as an argument. You
421can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000422.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423which is useful to seeing what files the process is referencing.
424Furthermore, using the abbreviation will ensure that you don't
425accidentally forget to include a call like
426.B lstat
427in the list. Betchya woulda forgot that one.
428.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000429.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430Trace all system calls which involve process management. This
431is useful for watching the fork, wait, and exec steps of a process.
432.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000433.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434Trace all the network related system calls.
435.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000436.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437Trace all signal related system calls.
438.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000439.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440Trace all IPC related system calls.
441.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000442.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000443Trace all file descriptor related system calls.
444.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000445\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000447The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000448.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000449The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000451option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000452.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000453.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000454\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000456default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000457.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000458.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000459\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000460Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461This option has the effect of causing all arguments to be printed
462in hexadecimal. This is mostly useful if you don't trust the
463decoding or you need to know the actual numeric value of an
464argument.
465.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000466\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000467Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000468.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000469For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000470.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000471(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000472.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000473causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000475\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000476Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000477file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000478all input activity on file descriptors
479.I 3
480and
481.I 5
482use
483\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000484Note that this is independent from the normal tracing of the
485.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000487.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000489\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000490Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000492all output activity on file descriptors
493.I 3
494and
495.I 5
496use
497\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000498Note that this is independent from the normal tracing of the
499.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000501.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502.TP
503.BI "\-o " filename
504Write the trace output to the file
505.I filename
506rather than to stderr.
507Use
508.I filename.pid
509if
510.B \-ff
511is used.
512If the argument begins with `|' or with `!' then the rest of the
513argument is treated as a command and all output is piped to it.
514This is convenient for piping the debugging output to a program
515without affecting the redirections of executed programs.
516.TP
517.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000518Set the overhead for tracing system calls to
519.I overhead
520microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521This is useful for overriding the default heuristic for guessing
522how much time is spent in mere measuring when timing system calls using
523the
524.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000525option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000526program run without tracing (using
527.BR time (1))
528and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000530.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531.TP
532.BI "\-p " pid
533Attach to the process with the process
534.SM ID
535.I pid
536and begin tracing.
537The trace may be terminated
538at any time by a keyboard interrupt signal (\c
539.SM CTRL\s0-C).
540.B strace
541will respond by detaching itself from the traced process(es)
542leaving it (them) to continue running.
543Multiple
544.B \-p
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100545options can be used to attach to up to 32 processes.
546-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000548.BI "\-P " path
549Trace only system calls accessing
550.I path.
551Multiple
552.B \-P
553options can be used to specify up to 256 paths.
554.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000555.BI "\-s " strsize
556Specify the maximum string size to print (the default is 32). Note
557that filenames are not considered strings and are always printed in
558full.
559.TP
560.BI "\-S " sortby
561Sort the output of the histogram printed by the
562.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000563option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000564.BR time ,
565.BR calls ,
566.BR name ,
567and
568.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000569(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000570.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571.TP
572.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000573Run command with the user \s-1ID\s0, group \s-2ID\s0, and
574supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575.IR username .
576This option is only useful when running as root and enables the
577correct execution of setuid and/or setgid binaries.
578Unless this option is used setuid and setgid programs are executed
579without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000580.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000581\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000582Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000583.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000584in its list of environment variables.
585.TP
586.BI "\-E " var
587Remove
588.IR var
589from the inherited list of environment variables before passing it on to
590the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000591.SH DIAGNOSTICS
592When
593.I command
594exits,
595.B strace
596exits with the same exit status.
597If
598.I command
599is terminated by a signal,
600.B strace
601terminates itself with the same signal, so that
602.B strace
603can be used as a wrapper process transparent to the invoking parent process.
604.LP
605When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000606.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000607the exit status of
608.B strace
609is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000610.SH "SETUID INSTALLATION"
611If
612.B strace
613is installed setuid to root then the invoking user will be able to
614attach to and trace processes owned by any user.
615In addition setuid and setgid programs will be executed and traced
616with the correct effective privileges.
617Since only users trusted with full root privileges should be allowed
618to do these things,
619it only makes sense to install
620.B strace
621as setuid to root when the users who can execute it are restricted
622to those users who have this trust.
623For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000624.B strace
625with mode `rwsr-xr--', user
626.B root
627and group
628.BR trace ,
629where members of the
630.B trace
631group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000632If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000633a non-setuid version of
634.B strace
635for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000637.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000638.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000639.BR ptrace (2),
640.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000641.SH NOTES
642It is a pity that so much tracing clutter is produced by systems
643employing shared libraries.
644.LP
645It is instructive to think about system call inputs and outputs
646as data-flow across the user/kernel boundary. Because user-space
647and kernel-space are separate and address-protected, it is
648sometimes possible to make deductive inferences about process
649behavior using inputs and outputs as propositions.
650.LP
651In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000652or have a different name. For example, on System V-derived systems
653the true
654.BR time (2)
655system call does not take an argument and the
656.B stat
657function is called
658.B xstat
659and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000660discrepancies are normal but idiosyncratic characteristics of the
661system call interface and are accounted for by C library wrapper
662functions.
663.LP
664On some platforms a process that has a system call trace applied
665to it with the
666.B \-p
667option will receive a
668.BR \s-1SIGSTOP\s0 .
669This signal may interrupt a system call that is not restartable.
670This may have an unpredictable effect on the process
671if the process takes no action to restart the system call.
672.SH BUGS
673Programs that use the
674.I setuid
675bit do not have
676effective user
677.SM ID
678privileges while being traced.
679.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000680A traced process runs slowly.
681.LP
682Traced processes which are descended from
683.I command
684may be left running after an interrupt signal (\c
685.SM CTRL\s0-C).
686.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000687The
688.B \-i
689option is weakly supported.
690.SH HISTORY
691.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000692The original
693.B strace
694was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000696The SunOS version of
697.B strace
698was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000699by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000700Even though Paul released
701.B strace
7022.5 in 1992,
703Branko's work was based on Paul's
704.B strace
7051.5 release from 1991.
706In 1993, Rick Sladkey merged
707.B strace
7082.5 for SunOS and the second release of
709.B strace
710for Linux, added many of the features of
711.BR truss (1)
712from SVR4, and produced an
713.B strace
714that worked on both platforms. In 1994 Rick ported
715.B strace
716to SVR4 and Solaris and wrote the
717automatic configuration support. In 1995 he ported
718.B strace
719to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720and tired of writing about himself in the third person.
721.SH PROBLEMS
722Problems with
723.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100724should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000725.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000726mailing list at <strace\-devel@lists.sourceforge.net>.