blob: 5f287d78dd03b9e3e6145e390195c95a368cd0dc [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]
Denys Vlasenko22efaf02013-02-27 12:15:19 +010044[\fB-b\fIexecve\fR]
45[\fB-e\fIexpr\fR]...
46[\fB-a\fIcolumn\fR]
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020047[\fB-o\fIfile\fR]
48[\fB-s\fIstrsize\fR]
49[\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
50[\fB-D\fR]
51[\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
52\fIcommand\fR [\fIargs\fR]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053.sp
54.B strace
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020055\fB-c\fR[\fBdf\fR]
56[\fB-I\fIn\fR]
Denys Vlasenko22efaf02013-02-27 12:15:19 +010057[\fB-b\fIexecve\fR]
58[\fB-e\fIexpr\fR]...
59[\fB-O\fIoverhead\fR]
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +020060[\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
61[\fB-D\fR]
62[\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
63\fIcommand\fR [\fIargs\fR]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000064.SH DESCRIPTION
65.IX "strace command" "" "\fLstrace\fR command"
66.LP
67In the simplest case
68.B strace
69runs the specified
70.I command
71until it exits.
72It intercepts and records the system calls which are called
73by a process and the signals which are received by a process.
74The name of each system call, its arguments and its return value
75are printed on standard error or to the file specified with the
76.B \-o
Roland McGratha09353a2008-12-10 06:09:29 +000077option.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078.LP
79.B strace
Nate Sammonsb4aa1131999-03-31 05:59:04 +000080is a useful diagnostic, instructional, and debugging tool.
Roland McGrath0411b402003-10-22 06:16:32 +000081System administrators, diagnosticians and trouble-shooters will find
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082it invaluable for solving problems with
83programs for which the source is not readily available since
84they do not need to be recompiled in order to trace them.
85Students, hackers and the overly-curious will find that
86a great deal can be learned about a system and its system calls by
87tracing even ordinary programs. And programmers will find that
88since system calls and signals are events that happen at the user/kernel
89interface, a close examination of this boundary is very
90useful for bug isolation, sanity checking and
91attempting to capture race conditions.
92.LP
93Each line in the trace contains the system call name, followed
94by its arguments in parentheses and its return value.
95An example from stracing the command ``cat /dev/null'' is:
96.CW
97open("/dev/null", O_RDONLY) = 3
98.CE
99Errors (typically a return value of \-1) have the errno symbol
100and error string appended.
101.CW
102open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
103.CE
104Signals are printed as a signal symbol and a signal string.
105An excerpt from stracing and interrupting the command ``sleep 666'' is:
106.CW
107sigsuspend([] <unfinished ...>
108--- SIGINT (Interrupt) ---
109+++ killed by SIGINT +++
110.CE
Jan Kratochvil14256a72008-09-12 08:44:30 +0000111If a system call is being executed and meanwhile another one is being called
112from a different thread/process then
113.B strace
114will try to preserve the order of those events and mark the ongoing call as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000115being
116.IR unfinished .
117When the call returns it will be marked as
118.IR resumed .
Jan Kratochvil14256a72008-09-12 08:44:30 +0000119.CW
120[pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
121[pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
122[pid 28772] <... select resumed> ) = 1 (in [3])
123.CE
124Interruption of a (restartable) system call by a signal delivery is processed
125differently as kernel terminates the system call and also arranges its
126immediate reexecution after the signal handler completes.
127.CW
128read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
129--- SIGALRM (Alarm clock) @ 0 (0) ---
130rt_sigreturn(0xe) = 0
131read(0, ""..., 1) = 0
132.CE
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133Arguments are printed in symbolic form with a passion.
Roland McGrath0411b402003-10-22 06:16:32 +0000134This example shows the shell performing ``>>xyzzy'' output redirection:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000135.CW
136open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
137.CE
Dmitry V. Levin9b3eb842012-02-22 00:29:44 +0000138Here the third argument of open is decoded by breaking down the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139flag argument into its three bitwise-OR constituents and printing the
140mode value in octal by tradition. Where traditional or native
141usage differs from ANSI or POSIX, the latter forms are preferred.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000142In some cases,
143.B strace
144output has proven to be more readable than the source.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145.LP
146Structure pointers are dereferenced and the members are displayed
147as appropriate. In all cases arguments are formatted in the most C-like
148fashion possible.
149For example, the essence of the command ``ls \-l /dev/null'' is captured as:
150.CW
151lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
152.CE
153Notice how the `struct stat' argument is dereferenced and how each member is
154displayed symbolically. In particular, observe how the st_mode member
155is carefully decoded into a bitwise-OR of symbolic and numeric values.
156Also notice in this example that the first argument to lstat is an input
157to the system call and the second argument is an output. Since output
Wichert Akkerman8829a551999-06-11 13:18:40 +0000158arguments are not modified if the system call fails, arguments may not
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159always be dereferenced. For example, retrying the ``ls \-l'' example
160with a non-existent file produces the following line:
161.CW
162lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
163.CE
164In this case the porch light is on but nobody is home.
165.LP
166Character pointers are dereferenced and printed as C strings.
167Non-printing characters in strings are normally represented by
168ordinary C escape codes.
169Only the first
170.I strsize
171(32 by default) bytes of strings are printed;
172longer strings have an ellipsis appended following the closing quote.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000173Here is a line from ``ls \-l'' where the
174.B getpwuid
175library routine is reading the password file:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176.CW
177read(3, "root::0:0:System Administrator:/"..., 1024) = 422
178.CE
179While structures are annotated using curly braces, simple pointers
180and arrays are printed using square brackets with commas separating
181elements. Here is an example from the command ``id'' on a system with
182supplementary group ids:
183.CW
184getgroups(32, [100, 0]) = 2
185.CE
186On the other hand, bit-sets are also shown using square brackets
187but set elements are separated only by a space. Here is the shell
188preparing to execute an external command:
189.CW
190sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
191.CE
192Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
193In some cases the bit-set is so full that printing out the unset
194elements is more valuable. In that case, the bit-set is prefixed by
195a tilde like this:
196.CW
197sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
198.CE
199Here the second argument represents the full set of all signals.
200.SH OPTIONS
201.TP 12
202.TP
203.B \-c
Roland McGrath4de04aa2004-08-31 07:47:47 +0000204Count time, calls, and errors for each system call and report a summary on
205program exit. On Linux, this attempts to show system time (CPU time spent
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000206running in the kernel) independent of wall clock time. If
207.B \-c
208is used with
209.B \-f
210or
211.B \-F
212(below), only aggregate totals for all traced processes are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000213.TP
Dmitry V. Levine3a7ef52010-03-28 19:24:54 +0000214.B \-C
215Like
216.B \-c
217but also print regular output while processes are running.
218.TP
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200219.B \-D
Andreas Schwabb87d30c2010-06-11 15:49:36 +0200220Run tracer process as a detached grandchild, not as parent of the
221tracee. This reduces the visible effect of
222.B strace
223by keeping the tracee a direct child of the calling process.
224.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000225.B \-d
Wichert Akkerman8829a551999-06-11 13:18:40 +0000226Show some debugging output of
227.B strace
228itself on the standard error.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229.TP
230.B \-f
231Trace child processes as they are created by currently traced
Wichert Akkerman8829a551999-06-11 13:18:40 +0000232processes as a result of the
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100233.BR fork (2),
234.BR vfork (2)
235and
236.BR clone (2)
237system calls. Note that
238.B \-p
239.I PID
240.B \-f
241will attach all threads of process PID if it is multi-threaded,
242not only thread with thread_id = PID.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243.TP
244.B \-ff
245If the
246.B \-o
247.I filename
248option is in effect, each processes trace is written to
249.I filename.pid
250where pid is the numeric process id of each process.
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000251This is incompatible with
252.BR \-c ,
253since no per-process counts are kept.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000254.TP
255.B \-F
Roland McGrath41c48222008-07-18 00:25:10 +0000256This option is now obsolete and it has the same functionality as
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000257.BR \-f .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258.TP
259.B \-h
260Print the help summary.
261.TP
262.B \-i
263Print the instruction pointer at the time of the system call.
264.TP
265.B \-q
266Suppress messages about attaching, detaching etc. This happens
267automatically when output is redirected to a file and the command
268is run directly instead of attaching.
269.TP
Daniel P. Berrange01997cf2013-05-13 11:30:55 +0100270.B \-qq
Dmitry V. Levine8ff4c62013-05-28 20:27:10 +0000271If given twice, suppress messages about process exit status.
Daniel P. Berrange01997cf2013-05-13 11:30:55 +0100272.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273.B \-r
274Print a relative timestamp upon entry to each system call. This
275records the time difference between the beginning of successive
276system calls.
277.TP
278.B \-t
279Prefix each line of the trace with the time of day.
280.TP
281.B \-tt
282If given twice, the time printed will include the microseconds.
283.TP
284.B \-ttt
285If given thrice, the time printed will include the microseconds
286and the leading portion will be printed as the number
287of seconds since the epoch.
288.TP
289.B \-T
290Show the time spent in system calls. This records the time
291difference between the beginning and the end of each system call.
292.TP
293.B \-v
294Print unabbreviated versions of environment, stat, termios, etc.
295calls. These structures are very common in calls and so the default
296behavior displays a reasonable subset of structure members. Use
297this option to get all of the gory details.
298.TP
299.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000300Print the version number of
301.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302.TP
303.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000304Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305.TP
306.B \-xx
307Print all strings in hexadecimal string format.
308.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000309.B \-y
310Print paths associated with file descriptor arguments.
311.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000313Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314.TP
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100315.BI "\-b " syscall
316If specified syscall is reached, detach from traced process.
317Currently, only
318.I execve
319syscall is supported. This option is useful if you want to trace
320multi-threaded process and therefore require -f, but don't want
321to trace its (potentially very complex) children.
322.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323.BI "\-e " expr
324A qualifying expression which modifies which events to trace
325or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000326.RS 15
327.IP
328[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
329.RE
330.IP
331where
332.I qualifier
333is one of
334.BR trace ,
335.BR abbrev ,
336.BR verbose ,
337.BR raw ,
338.BR signal ,
339.BR read ,
340or
341.B write
342and
343.I value
344is a qualifier-dependent symbol or number. The default
345qualifier is
346.BR trace .
347Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000348.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000349means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000350.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000351which in turn means trace only the
352.B open
353system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000354.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000355means to trace every system call except
356.BR open .
357In addition, the special values
358.B all
359and
360.B none
361have the obvious meanings.
362.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000363Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000364expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365the exclamation point with a backslash.
366.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000367\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000368Trace only the specified set of system calls. The
369.B \-c
370option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000371to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000372.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000373means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374trace those four system calls. Be careful when making inferences
375about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000376are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000377.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000379.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380Trace all system calls which take a file name as an argument. You
381can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000382.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383which is useful to seeing what files the process is referencing.
384Furthermore, using the abbreviation will ensure that you don't
385accidentally forget to include a call like
386.B lstat
387in the list. Betchya woulda forgot that one.
388.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000389.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390Trace all system calls which involve process management. This
391is useful for watching the fork, wait, and exec steps of a process.
392.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000393.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394Trace all the network related system calls.
395.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000396.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397Trace all signal related system calls.
398.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000399.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400Trace all IPC related system calls.
401.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000402.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000403Trace all file descriptor related system calls.
404.TP
Namhyung Kim96792962012-10-24 11:41:57 +0900405.BR "\-e\ trace" = memory
406Trace all memory mapping related system calls.
407.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000408\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000410The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000411.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000412The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000414option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000415.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000416.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000417\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000419default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000420.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000422\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000423Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424This option has the effect of causing all arguments to be printed
425in hexadecimal. This is mostly useful if you don't trust the
426decoding or you need to know the actual numeric value of an
427argument.
428.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000429\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000430Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000431.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000432For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000433.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000434(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000435.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000436causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000438\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000439Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000441all input activity on file descriptors
442.I 3
443and
444.I 5
445use
446\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000447Note that this is independent from the normal tracing of the
448.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000450.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000452\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000453Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000455all output activity on file descriptors
456.I 3
457and
458.I 5
459use
460\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000461Note that this is independent from the normal tracing of the
462.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000464.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465.TP
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +0200466.BI "\-I " interruptible
467When strace can be interrupted by signals (such as pressing ^C).
4681: no signals are blocked; 2: fatal signals are blocked while decoding syscall
469(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
4704: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
471strace -o FILE PROG not stop on ^Z).
472.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473.BI "\-o " filename
474Write the trace output to the file
475.I filename
476rather than to stderr.
477Use
478.I filename.pid
479if
480.B \-ff
481is used.
482If the argument begins with `|' or with `!' then the rest of the
483argument is treated as a command and all output is piped to it.
484This is convenient for piping the debugging output to a program
485without affecting the redirections of executed programs.
486.TP
487.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000488Set the overhead for tracing system calls to
489.I overhead
490microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491This is useful for overriding the default heuristic for guessing
492how much time is spent in mere measuring when timing system calls using
493the
494.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000495option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000496program run without tracing (using
497.BR time (1))
498and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000500.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501.TP
502.BI "\-p " pid
503Attach to the process with the process
504.SM ID
505.I pid
506and begin tracing.
507The trace may be terminated
508at any time by a keyboard interrupt signal (\c
509.SM CTRL\s0-C).
510.B strace
511will respond by detaching itself from the traced process(es)
512leaving it (them) to continue running.
513Multiple
514.B \-p
Denys Vlasenko94f00e62012-03-26 13:31:11 +0200515options can be used to attach to many processes.
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100516-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000518.BI "\-P " path
519Trace only system calls accessing
520.I path.
521Multiple
522.B \-P
Denys Vlasenko7239dbc2013-03-05 15:46:34 +0100523options can be used to specify several paths.
Grant Edwards8a082772011-04-07 20:25:40 +0000524.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525.BI "\-s " strsize
526Specify the maximum string size to print (the default is 32). Note
527that filenames are not considered strings and are always printed in
528full.
529.TP
530.BI "\-S " sortby
531Sort the output of the histogram printed by the
532.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000533option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000534.BR time ,
535.BR calls ,
536.BR name ,
537and
538.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000539(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000540.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541.TP
542.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000543Run command with the user \s-1ID\s0, group \s-2ID\s0, and
544supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545.IR username .
546This option is only useful when running as root and enables the
547correct execution of setuid and/or setgid binaries.
548Unless this option is used setuid and setgid programs are executed
549without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000550.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000551\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000552Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000553.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000554in its list of environment variables.
555.TP
556.BI "\-E " var
557Remove
558.IR var
559from the inherited list of environment variables before passing it on to
560the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000561.SH DIAGNOSTICS
562When
563.I command
564exits,
565.B strace
566exits with the same exit status.
567If
568.I command
569is terminated by a signal,
570.B strace
571terminates itself with the same signal, so that
572.B strace
573can be used as a wrapper process transparent to the invoking parent process.
574.LP
575When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000576.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000577the exit status of
578.B strace
579is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580.SH "SETUID INSTALLATION"
581If
582.B strace
583is installed setuid to root then the invoking user will be able to
584attach to and trace processes owned by any user.
585In addition setuid and setgid programs will be executed and traced
586with the correct effective privileges.
587Since only users trusted with full root privileges should be allowed
588to do these things,
589it only makes sense to install
590.B strace
591as setuid to root when the users who can execute it are restricted
592to those users who have this trust.
593For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000594.B strace
595with mode `rwsr-xr--', user
596.B root
597and group
598.BR trace ,
599where members of the
600.B trace
601group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000603a non-setuid version of
604.B strace
605for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000607.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000608.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000609.BR ptrace (2),
610.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611.SH NOTES
612It is a pity that so much tracing clutter is produced by systems
613employing shared libraries.
614.LP
615It is instructive to think about system call inputs and outputs
616as data-flow across the user/kernel boundary. Because user-space
617and kernel-space are separate and address-protected, it is
618sometimes possible to make deductive inferences about process
619behavior using inputs and outputs as propositions.
620.LP
621In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000622or have a different name. For example, on System V-derived systems
623the true
624.BR time (2)
625system call does not take an argument and the
626.B stat
627function is called
628.B xstat
629and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000630discrepancies are normal but idiosyncratic characteristics of the
631system call interface and are accounted for by C library wrapper
632functions.
633.LP
634On some platforms a process that has a system call trace applied
635to it with the
636.B \-p
637option will receive a
638.BR \s-1SIGSTOP\s0 .
639This signal may interrupt a system call that is not restartable.
640This may have an unpredictable effect on the process
641if the process takes no action to restart the system call.
642.SH BUGS
643Programs that use the
644.I setuid
645bit do not have
646effective user
647.SM ID
648privileges while being traced.
649.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000650A traced process runs slowly.
651.LP
652Traced processes which are descended from
653.I command
654may be left running after an interrupt signal (\c
655.SM CTRL\s0-C).
656.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000657The
658.B \-i
659option is weakly supported.
660.SH HISTORY
661.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000662The original
663.B strace
664was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000666The SunOS version of
667.B strace
668was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000669by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000670Even though Paul released
671.B strace
6722.5 in 1992,
673Branko's work was based on Paul's
674.B strace
6751.5 release from 1991.
676In 1993, Rick Sladkey merged
677.B strace
6782.5 for SunOS and the second release of
679.B strace
680for Linux, added many of the features of
681.BR truss (1)
682from SVR4, and produced an
683.B strace
684that worked on both platforms. In 1994 Rick ported
685.B strace
686to SVR4 and Solaris and wrote the
687automatic configuration support. In 1995 he ported
688.B strace
689to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000690and tired of writing about himself in the third person.
691.SH PROBLEMS
692Problems with
693.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100694should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000695.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000696mailing list at <strace\-devel@lists.sourceforge.net>.