blob: 00ca03c489d1ac1bbf9e68e40577bfa98bbfcd61 [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
270.B \-r
271Print a relative timestamp upon entry to each system call. This
272records the time difference between the beginning of successive
273system calls.
274.TP
275.B \-t
276Prefix each line of the trace with the time of day.
277.TP
278.B \-tt
279If given twice, the time printed will include the microseconds.
280.TP
281.B \-ttt
282If given thrice, the time printed will include the microseconds
283and the leading portion will be printed as the number
284of seconds since the epoch.
285.TP
286.B \-T
287Show the time spent in system calls. This records the time
288difference between the beginning and the end of each system call.
289.TP
290.B \-v
291Print unabbreviated versions of environment, stat, termios, etc.
292calls. These structures are very common in calls and so the default
293behavior displays a reasonable subset of structure members. Use
294this option to get all of the gory details.
295.TP
296.B \-V
Wichert Akkerman8829a551999-06-11 13:18:40 +0000297Print the version number of
298.BR strace .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299.TP
300.B \-x
Wichert Akkerman8829a551999-06-11 13:18:40 +0000301Print all non-ASCII strings in hexadecimal string format.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302.TP
303.B \-xx
304Print all strings in hexadecimal string format.
305.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000306.B \-y
307Print paths associated with file descriptor arguments.
308.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309.BI "\-a " column
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +0000310Align return values in a specific column (default column 40).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311.TP
Denys Vlasenko22efaf02013-02-27 12:15:19 +0100312.BI "\-b " syscall
313If specified syscall is reached, detach from traced process.
314Currently, only
315.I execve
316syscall is supported. This option is useful if you want to trace
317multi-threaded process and therefore require -f, but don't want
318to trace its (potentially very complex) children.
319.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320.BI "\-e " expr
321A qualifying expression which modifies which events to trace
322or how to trace them. The format of the expression is:
Wichert Akkerman8829a551999-06-11 13:18:40 +0000323.RS 15
324.IP
325[\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
326.RE
327.IP
328where
329.I qualifier
330is one of
331.BR trace ,
332.BR abbrev ,
333.BR verbose ,
334.BR raw ,
335.BR signal ,
336.BR read ,
337or
338.B write
339and
340.I value
341is a qualifier-dependent symbol or number. The default
342qualifier is
343.BR trace .
344Using an exclamation mark negates the set of values. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000345.BR \-e "\ " open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000346means literally
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000347.BR \-e "\ " trace = open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000348which in turn means trace only the
349.B open
350system call. By contrast,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000351.BR \-e "\ " trace "=!" open
Wichert Akkerman8829a551999-06-11 13:18:40 +0000352means to trace every system call except
353.BR open .
354In addition, the special values
355.B all
356and
357.B none
358have the obvious meanings.
359.IP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360Note that some shells use the exclamation point for history
Wichert Akkerman8829a551999-06-11 13:18:40 +0000361expansion even inside quoted arguments. If so, you must escape
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362the exclamation point with a backslash.
363.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000364\fB\-e\ trace\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365Trace only the specified set of system calls. The
366.B \-c
367option is useful for determining which system calls might be useful
Wichert Akkerman8829a551999-06-11 13:18:40 +0000368to trace. For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000369.BR trace = open,close,read,write
Wichert Akkerman8829a551999-06-11 13:18:40 +0000370means to only
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371trace those four system calls. Be careful when making inferences
372about the user/kernel boundary if only a subset of system calls
Wichert Akkerman8829a551999-06-11 13:18:40 +0000373are being monitored. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000374.BR trace = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000376.BR "\-e\ trace" = file
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377Trace all system calls which take a file name as an argument. You
378can think of this as an abbreviation for
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000379.BR "\-e\ trace" = open , stat , chmod , unlink ,...
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380which is useful to seeing what files the process is referencing.
381Furthermore, using the abbreviation will ensure that you don't
382accidentally forget to include a call like
383.B lstat
384in the list. Betchya woulda forgot that one.
385.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000386.BR "\-e\ trace" = process
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387Trace all system calls which involve process management. This
388is useful for watching the fork, wait, and exec steps of a process.
389.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000390.BR "\-e\ trace" = network
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391Trace all the network related system calls.
392.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000393.BR "\-e\ trace" = signal
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394Trace all signal related system calls.
395.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000396.BR "\-e\ trace" = ipc
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397Trace all IPC related system calls.
398.TP
Dmitry V. Levin1c3031b2011-01-14 17:17:20 +0000399.BR "\-e\ trace" = desc
Roland McGrath2fe7b132005-07-05 03:25:35 +0000400Trace all file descriptor related system calls.
401.TP
Namhyung Kim96792962012-10-24 11:41:57 +0900402.BR "\-e\ trace" = memory
403Trace all memory mapping related system calls.
404.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000405\fB\-e\ abbrev\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406Abbreviate the output from printing each member of large structures.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000407The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000408.BR abbrev = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000409The
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410.B \-v
Wichert Akkerman8829a551999-06-11 13:18:40 +0000411option has the effect of
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000412.BR abbrev = none .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000414\fB\-e\ verbose\fR=\fIset\fR
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415Dereference structures for the specified set of system calls. The
Wichert Akkerman8829a551999-06-11 13:18:40 +0000416default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000417.BR verbose = all .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000419\fB\-e\ raw\fR=\fIset\fR
Roland McGrath0411b402003-10-22 06:16:32 +0000420Print raw, undecoded arguments for the specified set of system calls.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421This option has the effect of causing all arguments to be printed
422in hexadecimal. This is mostly useful if you don't trust the
423decoding or you need to know the actual numeric value of an
424argument.
425.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000426\fB\-e\ signal\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000427Trace only the specified subset of signals. The default is
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000428.BR signal = all .
Wichert Akkerman8829a551999-06-11 13:18:40 +0000429For example,
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000430.B signal "=!" SIGIO
Wichert Akkerman8829a551999-06-11 13:18:40 +0000431(or
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000432.BR signal "=!" io )
Wichert Akkerman8829a551999-06-11 13:18:40 +0000433causes SIGIO signals not to be traced.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000435\fB\-e\ read\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000436Perform a full hexadecimal and ASCII dump of all the data read from
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000438all input activity on file descriptors
439.I 3
440and
441.I 5
442use
443\fB\-e\ read\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000444Note that this is independent from the normal tracing of the
445.BR read (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000447.BR -e "\ " trace = read .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000449\fB\-e\ write\fR=\fIset\fR
Wichert Akkerman8829a551999-06-11 13:18:40 +0000450Perform a full hexadecimal and ASCII dump of all the data written to
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451file descriptors listed in the specified set. For example, to see
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000452all output activity on file descriptors
453.I 3
454and
455.I 5
456use
457\fB\-e\ write\fR=\fI3\fR,\fI5\fR.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000458Note that this is independent from the normal tracing of the
459.BR write (2)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460system call which is controlled by the option
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000461.BR -e "\ " trace = write .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462.TP
Denys Vlasenkoc5ccfa42012-03-26 13:10:50 +0200463.BI "\-I " interruptible
464When strace can be interrupted by signals (such as pressing ^C).
4651: no signals are blocked; 2: fatal signals are blocked while decoding syscall
466(default); 3: fatal signals are always blocked (default if '-o FILE PROG');
4674: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
468strace -o FILE PROG not stop on ^Z).
469.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470.BI "\-o " filename
471Write the trace output to the file
472.I filename
473rather than to stderr.
474Use
475.I filename.pid
476if
477.B \-ff
478is used.
479If the argument begins with `|' or with `!' then the rest of the
480argument is treated as a command and all output is piped to it.
481This is convenient for piping the debugging output to a program
482without affecting the redirections of executed programs.
483.TP
484.BI "\-O " overhead
Wichert Akkerman8829a551999-06-11 13:18:40 +0000485Set the overhead for tracing system calls to
486.I overhead
487microseconds.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488This is useful for overriding the default heuristic for guessing
489how much time is spent in mere measuring when timing system calls using
490the
491.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000492option. The accuracy of the heuristic can be gauged by timing a given
Wichert Akkerman8829a551999-06-11 13:18:40 +0000493program run without tracing (using
494.BR time (1))
495and comparing the accumulated
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496system call time to the total produced using
Wichert Akkerman8829a551999-06-11 13:18:40 +0000497.BR \-c .
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498.TP
499.BI "\-p " pid
500Attach to the process with the process
501.SM ID
502.I pid
503and begin tracing.
504The trace may be terminated
505at any time by a keyboard interrupt signal (\c
506.SM CTRL\s0-C).
507.B strace
508will respond by detaching itself from the traced process(es)
509leaving it (them) to continue running.
510Multiple
511.B \-p
Denys Vlasenko94f00e62012-03-26 13:31:11 +0200512options can be used to attach to many processes.
Denys Vlasenko6bc050c2012-03-13 11:48:22 +0100513-p "`pidof PROG`" syntax is supported.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514.TP
Grant Edwards8a082772011-04-07 20:25:40 +0000515.BI "\-P " path
516Trace only system calls accessing
517.I path.
518Multiple
519.B \-P
Denys Vlasenko7239dbc2013-03-05 15:46:34 +0100520options can be used to specify several paths.
Grant Edwards8a082772011-04-07 20:25:40 +0000521.TP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522.BI "\-s " strsize
523Specify the maximum string size to print (the default is 32). Note
524that filenames are not considered strings and are always printed in
525full.
526.TP
527.BI "\-S " sortby
528Sort the output of the histogram printed by the
529.B \-c
Roland McGrath0411b402003-10-22 06:16:32 +0000530option by the specified criterion. Legal values are
Wichert Akkerman8829a551999-06-11 13:18:40 +0000531.BR time ,
532.BR calls ,
533.BR name ,
534and
535.B nothing
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000536(default is
Wichert Akkerman8829a551999-06-11 13:18:40 +0000537.BR time ).
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538.TP
539.BI "\-u " username
Wichert Akkerman8829a551999-06-11 13:18:40 +0000540Run command with the user \s-1ID\s0, group \s-2ID\s0, and
541supplementary groups of
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542.IR username .
543This option is only useful when running as root and enables the
544correct execution of setuid and/or setgid binaries.
545Unless this option is used setuid and setgid programs are executed
546without effective privileges.
Roland McGrath4417fda2003-01-24 04:31:20 +0000547.TP
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000548\fB\-E\ \fIvar\fR=\fIval\fR
Roland McGrath4417fda2003-01-24 04:31:20 +0000549Run command with
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000550.IR var = val
Roland McGrath4417fda2003-01-24 04:31:20 +0000551in its list of environment variables.
552.TP
553.BI "\-E " var
554Remove
555.IR var
556from the inherited list of environment variables before passing it on to
557the command.
Roland McGratha09353a2008-12-10 06:09:29 +0000558.SH DIAGNOSTICS
559When
560.I command
561exits,
562.B strace
563exits with the same exit status.
564If
565.I command
566is terminated by a signal,
567.B strace
568terminates itself with the same signal, so that
569.B strace
570can be used as a wrapper process transparent to the invoking parent process.
571.LP
572When using
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000573.BR \-p ,
Roland McGratha09353a2008-12-10 06:09:29 +0000574the exit status of
575.B strace
576is zero unless there was an unexpected error in doing the tracing.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577.SH "SETUID INSTALLATION"
578If
579.B strace
580is installed setuid to root then the invoking user will be able to
581attach to and trace processes owned by any user.
582In addition setuid and setgid programs will be executed and traced
583with the correct effective privileges.
584Since only users trusted with full root privileges should be allowed
585to do these things,
586it only makes sense to install
587.B strace
588as setuid to root when the users who can execute it are restricted
589to those users who have this trust.
590For example, it makes sense to install a special version of
Wichert Akkerman8829a551999-06-11 13:18:40 +0000591.B strace
592with mode `rwsr-xr--', user
593.B root
594and group
595.BR trace ,
596where members of the
597.B trace
598group are trusted users.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599If you do use this feature, please remember to install
Wichert Akkerman8829a551999-06-11 13:18:40 +0000600a non-setuid version of
601.B strace
602for ordinary lusers to use.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603.SH "SEE ALSO"
Roland McGrath7f7f4362005-12-02 03:59:35 +0000604.BR ltrace (1),
Wichert Akkerman8829a551999-06-11 13:18:40 +0000605.BR time (1),
Roland McGrath7f7f4362005-12-02 03:59:35 +0000606.BR ptrace (2),
607.BR proc (5)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608.SH NOTES
609It is a pity that so much tracing clutter is produced by systems
610employing shared libraries.
611.LP
612It is instructive to think about system call inputs and outputs
613as data-flow across the user/kernel boundary. Because user-space
614and kernel-space are separate and address-protected, it is
615sometimes possible to make deductive inferences about process
616behavior using inputs and outputs as propositions.
617.LP
618In some cases, a system call will differ from the documented behavior
Wichert Akkerman8829a551999-06-11 13:18:40 +0000619or have a different name. For example, on System V-derived systems
620the true
621.BR time (2)
622system call does not take an argument and the
623.B stat
624function is called
625.B xstat
626and takes an extra leading argument. These
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000627discrepancies are normal but idiosyncratic characteristics of the
628system call interface and are accounted for by C library wrapper
629functions.
630.LP
631On some platforms a process that has a system call trace applied
632to it with the
633.B \-p
634option will receive a
635.BR \s-1SIGSTOP\s0 .
636This signal may interrupt a system call that is not restartable.
637This may have an unpredictable effect on the process
638if the process takes no action to restart the system call.
639.SH BUGS
640Programs that use the
641.I setuid
642bit do not have
643effective user
644.SM ID
645privileges while being traced.
646.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000647A traced process runs slowly.
648.LP
649Traced processes which are descended from
650.I command
651may be left running after an interrupt signal (\c
652.SM CTRL\s0-C).
653.LP
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000654The
655.B \-i
656option is weakly supported.
657.SH HISTORY
658.B strace
Wichert Akkerman8829a551999-06-11 13:18:40 +0000659The original
660.B strace
661was written by Paul Kranenburg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000662for SunOS and was inspired by its trace utility.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000663The SunOS version of
664.B strace
665was ported to Linux and enhanced
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000666by Branko Lankester, who also wrote the Linux kernel support.
Wichert Akkerman8829a551999-06-11 13:18:40 +0000667Even though Paul released
668.B strace
6692.5 in 1992,
670Branko's work was based on Paul's
671.B strace
6721.5 release from 1991.
673In 1993, Rick Sladkey merged
674.B strace
6752.5 for SunOS and the second release of
676.B strace
677for Linux, added many of the features of
678.BR truss (1)
679from SVR4, and produced an
680.B strace
681that worked on both platforms. In 1994 Rick ported
682.B strace
683to SVR4 and Solaris and wrote the
684automatic configuration support. In 1995 he ported
685.B strace
686to Irix
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000687and tired of writing about himself in the third person.
688.SH PROBLEMS
689Problems with
690.B strace
Dmitry V. Levindd762c32012-02-25 15:29:21 +0100691should be reported to the
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692.B strace
Dmitry V. Levina7835e62010-03-31 17:26:49 +0000693mailing list at <strace\-devel@lists.sourceforge.net>.