blob: 9d628a1854dd96bce7a5b37caf64b9bc9f23d652 [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
271If given twice, suppress messages about process exit status and
272signals received.
273.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274.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
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100316.BI "\-b " syscall
317If specified syscall is reached, detach from traced process.
318Currently, only
319.I execve
320syscall is supported. This option is useful if you want to trace
321multi-threaded process and therefore require -f, but don't want
322to trace its (potentially very complex) children.
323.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324.BI "\-e " expr
325A qualifying expression which modifies which events to trace
326or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000327.RS 15
328.IP
329[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
330.RE
331.IP
332where
333.I qualifier
334is one of
335.BR trace ,
336.BR abbrev ,
337.BR verbose ,
338.BR raw ,
339.BR signal ,
340.BR read ,
341or
342.B write
343and
344.I value
345is a qualifier-dependent symbol or number. The default
346qualifier is
347.BR trace .
348Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000349.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000350means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000351.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000352which in turn means trace only the
353.B open
354system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000355.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000356means to trace every system call except
357.BR open .
358In addition, the special values
359.B all
360and
361.B none
362have the obvious meanings.
363.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000365expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366the exclamation point with a backslash.
367.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000368\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369Trace only the specified set of system calls. The
370.B \-c
371option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000372to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000373.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000374means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375trace those four system calls. Be careful when making inferences
376about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000377are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000378.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000380.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381Trace all system calls which take a file name as an argument. You
382can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000383.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384which is useful to seeing what files the process is referencing.
385Furthermore, using the abbreviation will ensure that you don't
386accidentally forget to include a call like
387.B lstat
388in the list. Betchya woulda forgot that one.
389.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000390.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391Trace all system calls which involve process management. This
392is useful for watching the fork, wait, and exec steps of a process.
393.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000394.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395Trace all the network related system calls.
396.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000397.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000398Trace all signal related system calls.
399.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000400.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401Trace all IPC related system calls.
402.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000403.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000404Trace all file descriptor related system calls.
405.TP
Namhyung Kim96792962012-10-24 11:41:57 +0900406.BR "\-e\ trace" = memory
407Trace all memory mapping related system calls.
408.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000409\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000411The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000412.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000413The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000415option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000416.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000418\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000420default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000421.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000423\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000424Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425This option has the effect of causing all arguments to be printed
426in hexadecimal. This is mostly useful if you don't trust the
427decoding or you need to know the actual numeric value of an
428argument.
429.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000430\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000431Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000432.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000433For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000434.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000435(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000436.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000437causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000439\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000440Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000441file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000442all input activity on file descriptors
443.I 3
444and
445.I 5
446use
447\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000448Note that this is independent from the normal tracing of the
449.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000451.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000453\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000454Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000456all output activity on file descriptors
457.I 3
458and
459.I 5
460use
461\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000462Note that this is independent from the normal tracing of the
463.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000465.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466.TP
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +0200467.BI "\-I " interruptible
468When strace can be interrupted by signals (such as pressing ^C).
4691: no signals are blocked; 2: fatal signals are blocked while decoding syscall
470(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
4714: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
472strace -o FILE PROG not stop on ^Z).
473.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474.BI "\-o " filename
475Write the trace output to the file
476.I filename
477rather than to stderr.
478Use
479.I filename.pid
480if
481.B \-ff
482is used.
483If the argument begins with `|' or with `!' then the rest of the
484argument is treated as a command and all output is piped to it.
485This is convenient for piping the debugging output to a program
486without affecting the redirections of executed programs.
487.TP
488.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000489Set the overhead for tracing system calls to
490.I overhead
491microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492This is useful for overriding the default heuristic for guessing
493how much time is spent in mere measuring when timing system calls using
494the
495.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000496option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000497program run without tracing (using
498.BR time (1))
499and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000501.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502.TP
503.BI "\-p " pid
504Attach to the process with the process
505.SM ID
506.I pid
507and begin tracing.
508The trace may be terminated
509at any time by a keyboard interrupt signal (\c
510.SM CTRL\s0-C).
511.B strace
512will respond by detaching itself from the traced process(es)
513leaving it (them) to continue running.
514Multiple
515.B \-p
Denys Vlasenko94f00e62012-03-26 13:31:11 +0200516options can be used to attach to many processes.
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100517-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000519.BI "\-P " path
520Trace only system calls accessing
521.I path.
522Multiple
523.B \-P
Denys Vlasenko7239dbc2013-03-05 15:46:34 +0100524options can be used to specify several paths.
Grant Edwards8a082772011-04-07 20:25:40 +0000525.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526.BI "\-s " strsize
527Specify the maximum string size to print (the default is 32). Note
528that filenames are not considered strings and are always printed in
529full.
530.TP
531.BI "\-S " sortby
532Sort the output of the histogram printed by the
533.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000534option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000535.BR time ,
536.BR calls ,
537.BR name ,
538and
539.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000540(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000541.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542.TP
543.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000544Run command with the user \s-1ID\s0, group \s-2ID\s0, and
545supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546.IR username .
547This option is only useful when running as root and enables the
548correct execution of setuid and/or setgid binaries.
549Unless this option is used setuid and setgid programs are executed
550without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000551.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000552\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000553Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000554.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000555in its list of environment variables.
556.TP
557.BI "\-E " var
558Remove
559.IR var
560from the inherited list of environment variables before passing it on to
561the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000562.SH DIAGNOSTICS
563When
564.I command
565exits,
566.B strace
567exits with the same exit status.
568If
569.I command
570is terminated by a signal,
571.B strace
572terminates itself with the same signal, so that
573.B strace
574can be used as a wrapper process transparent to the invoking parent process.
575.LP
576When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000577.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000578the exit status of
579.B strace
580is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581.SH "SETUID INSTALLATION"
582If
583.B strace
584is installed setuid to root then the invoking user will be able to
585attach to and trace processes owned by any user.
586In addition setuid and setgid programs will be executed and traced
587with the correct effective privileges.
588Since only users trusted with full root privileges should be allowed
589to do these things,
590it only makes sense to install
591.B strace
592as setuid to root when the users who can execute it are restricted
593to those users who have this trust.
594For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000595.B strace
596with mode `rwsr-xr--', user
597.B root
598and group
599.BR trace ,
600where members of the
601.B trace
602group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000604a non-setuid version of
605.B strace
606for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000607.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000608.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000609.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000610.BR ptrace (2),
611.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612.SH NOTES
613It is a pity that so much tracing clutter is produced by systems
614employing shared libraries.
615.LP
616It is instructive to think about system call inputs and outputs
617as data-flow across the user/kernel boundary. Because user-space
618and kernel-space are separate and address-protected, it is
619sometimes possible to make deductive inferences about process
620behavior using inputs and outputs as propositions.
621.LP
622In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000623or have a different name. For example, on System V-derived systems
624the true
625.BR time (2)
626system call does not take an argument and the
627.B stat
628function is called
629.B xstat
630and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631discrepancies are normal but idiosyncratic characteristics of the
632system call interface and are accounted for by C library wrapper
633functions.
634.LP
635On some platforms a process that has a system call trace applied
636to it with the
637.B \-p
638option will receive a
639.BR \s-1SIGSTOP\s0 .
640This signal may interrupt a system call that is not restartable.
641This may have an unpredictable effect on the process
642if the process takes no action to restart the system call.
643.SH BUGS
644Programs that use the
645.I setuid
646bit do not have
647effective user
648.SM ID
649privileges while being traced.
650.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000651A traced process runs slowly.
652.LP
653Traced processes which are descended from
654.I command
655may be left running after an interrupt signal (\c
656.SM CTRL\s0-C).
657.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000658The
659.B \-i
660option is weakly supported.
661.SH HISTORY
662.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000663The original
664.B strace
665was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000667The SunOS version of
668.B strace
669was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000670by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000671Even though Paul released
672.B strace
6732.5 in 1992,
674Branko's work was based on Paul's
675.B strace
6761.5 release from 1991.
677In 1993, Rick Sladkey merged
678.B strace
6792.5 for SunOS and the second release of
680.B strace
681for Linux, added many of the features of
682.BR truss (1)
683from SVR4, and produced an
684.B strace
685that worked on both platforms. In 1994 Rick ported
686.B strace
687to SVR4 and Solaris and wrote the
688automatic configuration support. In 1995 he ported
689.B strace
690to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000691and tired of writing about himself in the third person.
692.SH PROBLEMS
693Problems with
694.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100695should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000697mailing list at <strace\-devel@lists.sourceforge.net>.