1STRACE(1) General Commands Manual STRACE(1)
2
3
4
6 strace - trace system calls and signals
7
9 strace [ -dffhiqrtttTvxx ] [ -acolumn ] [ -eexpr ] ... [ -ofile ] [
10 -ppid ] ... [ -sstrsize ] [ -uusername ] [ -Evar=val ] ... [ -Evar ]
11 ... [ command [ arg ... ] ]
12
13 strace -c [ -eexpr ] ... [ -Ooverhead ] [ -Ssortby ] [ command [ arg
14 ... ] ]
15
17 In the simplest case strace runs the specified command until it exits.
18 It intercepts and records the system calls which are called by a
19 process and the signals which are received by a process. The name of
20 each system call, its arguments and its return value are printed on
21 standard error or to the file specified with the -o option.
22
23 strace is a useful diagnostic, instructional, and debugging tool. Sys‐
24 tem administrators, diagnosticians and trouble-shooters will find it
25 invaluable for solving problems with programs for which the source is
26 not readily available since they do not need to be recompiled in order
27 to trace them. Students, hackers and the overly-curious will find that
28 a great deal can be learned about a system and its system calls by
29 tracing even ordinary programs. And programmers will find that since
30 system calls and signals are events that happen at the user/kernel
31 interface, a close examination of this boundary is very useful for bug
32 isolation, sanity checking and attempting to capture race conditions.
33
34 Each line in the trace contains the system call name, followed by its
35 arguments in parentheses and its return value. An example from strac‐
36 ing the command ``cat /dev/null'' is:
37
38 open("/dev/null", O_RDONLY) = 3
39
40 Errors (typically a return value of -1) have the errno symbol and error
41 string appended.
42
43 open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
44
45 Signals are printed as a signal symbol and a signal string. An excerpt
46 from stracing and interrupting the command ``sleep 666'' is:
47
48 sigsuspend([] <unfinished ...>
49 --- SIGINT (Interrupt) ---
50 +++ killed by SIGINT +++
51
52 Arguments are printed in symbolic form with a passion. This example
53 shows the shell performing ``>>xyzzy'' output redirection:
54
55 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
56
57 Here the three argument form of open is decoded by breaking down the
58 flag argument into its three bitwise-OR constituents and printing the
59 mode value in octal by tradition. Where traditional or native usage
60 differs from ANSI or POSIX, the latter forms are preferred. In some
61 cases, strace output has proven to be more readable than the source.
62
63 Structure pointers are dereferenced and the members are displayed as
64 appropriate. In all cases arguments are formatted in the most C-like
65 fashion possible. For example, the essence of the command ``ls -l
66 /dev/null'' is captured as:
67
68 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
69
70 Notice how the `struct stat' argument is dereferenced and how each mem‐
71 ber is displayed symbolically. In particular, observe how the st_mode
72 member is carefully decoded into a bitwise-OR of symbolic and numeric
73 values. Also notice in this example that the first argument to lstat
74 is an input to the system call and the second argument is an output.
75 Since output arguments are not modified if the system call fails, argu‐
76 ments may not always be dereferenced. For example, retrying the ``ls
77 -l'' example with a non-existent file produces the following line:
78
79 lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
80
81 In this case the porch light is on but nobody is home.
82
83 Character pointers are dereferenced and printed as C strings. Non-
84 printing characters in strings are normally represented by ordinary C
85 escape codes. Only the first strsize (32 by default) bytes of strings
86 are printed; longer strings have an ellipsis appended following the
87 closing quote. Here is a line from ``ls -l'' where the getpwuid
88 library routine is reading the password file:
89
90 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
91
92 While structures are annotated using curly braces, simple pointers and
93 arrays are printed using square brackets with commas separating ele‐
94 ments. Here is an example from the command ``id'' on a system with
95 supplementary group ids:
96
97 getgroups(32, [100, 0]) = 2
98
99 On the other hand, bit-sets are also shown using square brackets but
100 set elements are separated only by a space. Here is the shell prepar‐
101 ing to execute an external command:
102
103 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
104
105 Here the second argument is a bit-set of two signals, SIGCHLD and SIGT‐
106 TOU. In some cases the bit-set is so full that printing out the unset
107 elements is more valuable. In that case, the bit-set is prefixed by a
108 tilde like this:
109
110 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
111
112 Here the second argument represents the full set of all signals.
113
115 -c Count time, calls, and errors for each system call
116 and report a summary on program exit. On Linux,
117 this attempts to show system time (CPU time spent
118 running in the kernel) independent of wall clock
119 time. If -c is used with -f or -F (below), only
120 aggregate totals for all traced processes are kept.
121
122 -d Show some debugging output of strace itself on the
123 standard error.
124
125 -f Trace child processes as they are created by cur‐
126 rently traced processes as a result of the fork(2)
127 system call. The new process is attached to as soon
128 as its pid is known (through the return value of
129 fork(2) in the parent process). This means that such
130 children may run uncontrolled for a while (espe‐
131 cially in the case of a vfork(2)), until the parent
132 is scheduled again to complete its (v)fork(2) call.
133 If the parent process decides to wait(2) for a child
134 that is currently being traced, it is suspended
135 until an appropriate child process either terminates
136 or incurs a signal that would cause it to terminate
137 (as determined from the child's current signal dis‐
138 position).
139
140 -ff If the -o filename option is in effect, each pro‐
141 cesses trace is written to filename.pid where pid is
142 the numeric process id of each process. This is
143 incompatible with -c, since no per-process counts
144 are kept.
145
146 -F Attempt to follow vforks. (On SunOS 4.x, this is
147 accomplished with some dynamic linking trickery.)
148 Otherwise, vforks will not be followed even if -f
149 has been given.
150
151 -h Print the help summary.
152
153 -i Print the instruction pointer at the time of the
154 system call.
155
156 -q Suppress messages about attaching, detaching etc.
157 This happens automatically when output is redirected
158 to a file and the command is run directly instead of
159 attaching.
160
161 -r Print a relative timestamp upon entry to each system
162 call. This records the time difference between the
163 beginning of successive system calls.
164
165 -t Prefix each line of the trace with the time of day.
166
167 -tt If given twice, the time printed will include the
168 microseconds.
169
170 -ttt If given thrice, the time printed will include the
171 microseconds and the leading portion will be printed
172 as the number of seconds since the epoch.
173
174 -T Show the time spent in system calls. This records
175 the time difference between the beginning and the
176 end of each system call.
177
178 -v Print unabbreviated versions of environment, stat,
179 termios, etc. calls. These structures are very
180 common in calls and so the default behavior displays
181 a reasonable subset of structure members. Use this
182 option to get all of the gory details.
183
184 -V Print the version number of strace.
185
186 -x Print all non-ASCII strings in hexadecimal string
187 format.
188
189 -xx Print all strings in hexadecimal string format.
190
191 -a column Align return values in a specific column (default
192 column 40).
193
194 -e expr A qualifying expression which modifies which events
195 to trace or how to trace them. The format of the
196 expression is:
197
198 [qualifier=][!]value1[,value2]...
199
200 where qualifier is one of trace, abbrev, verbose,
201 raw, signal, read, or write and value is a quali‐
202 fier-dependent symbol or number. The default quali‐
203 fier is trace. Using an exclamation mark negates
204 the set of values. For example, -eopen means liter‐
205 ally -e trace=open which in turn means trace only
206 the open system call. By contrast, -etrace=!open
207 means to trace every system call except open. In
208 addition, the special values all and none have the
209 obvious meanings.
210
211 Note that some shells use the exclamation point for
212 history expansion even inside quoted arguments. If
213 so, you must escape the exclamation point with a
214 backslash.
215
216 -e trace=set
217 Trace only the specified set of system calls. The
218 -c option is useful for determining which system
219 calls might be useful to trace. For example,
220 trace=open,close,read,write means to only trace
221 those four system calls. Be careful when making
222 inferences about the user/kernel boundary if only a
223 subset of system calls are being monitored. The
224 default is trace=all.
225
226 -e trace=file
227 Trace all system calls which take a file name as an
228 argument. You can think of this as an abbreviation
229 for -e trace=open,stat,chmod,unlink,... which is
230 useful to seeing what files the process is referenc‐
231 ing. Furthermore, using the abbreviation will
232 ensure that you don't accidentally forget to include
233 a call like lstat in the list. Betchya woulda for‐
234 got that one.
235
236 -e trace=process
237 Trace all system calls which involve process manage‐
238 ment. This is useful for watching the fork, wait,
239 and exec steps of a process.
240
241 -e trace=network
242 Trace all the network related system calls.
243
244 -e trace=signal
245 Trace all signal related system calls.
246
247 -e trace=ipc
248 Trace all IPC related system calls.
249
250 -e trace=desc
251 Trace all file descriptor related system calls.
252
253 -e abbrev=set
254 Abbreviate the output from printing each member of
255 large structures. The default is abbrev=all. The
256 -v option has the effect of abbrev=none.
257
258 -e verbose=set
259 Dereference structures for the specified set of sys‐
260 tem calls. The default is verbose=all.
261
262 -e raw=set Print raw, undecoded arguments for the specified set
263 of system calls. This option has the effect of
264 causing all arguments to be printed in hexadecimal.
265 This is mostly useful if you don't trust the decod‐
266 ing or you need to know the actual numeric value of
267 an argument.
268
269 -e signal=set
270 Trace only the specified subset of signals. The
271 default is signal=all. For example, signal=!SIGIO
272 (or signal=!io) causes SIGIO signals not to be
273 traced.
274
275 -e read=set Perform a full hexadecimal and ASCII dump of all the
276 data read from file descriptors listed in the speci‐
277 fied set. For example, to see all input activity on
278 file descriptors 3 and 5 use -e read=3,5. Note that
279 this is independent from the normal tracing of the
280 read(2) system call which is controlled by the
281 option -e trace=read.
282
283 -e write=set
284 Perform a full hexadecimal and ASCII dump of all the
285 data written to file descriptors listed in the spec‐
286 ified set. For example, to see all output activity
287 on file descriptors 3 and 5 use -e write=3,5. Note
288 that this is independent from the normal tracing of
289 the write(2) system call which is controlled by the
290 option -e trace=write.
291
292 -o filename Write the trace output to the file filename rather
293 than to stderr. Use filename.pid if -ff is used.
294 If the argument begins with `|' or with `!' then the
295 rest of the argument is treated as a command and all
296 output is piped to it. This is convenient for pip‐
297 ing the debugging output to a program without
298 affecting the redirections of executed programs.
299
300 -O overhead Set the overhead for tracing system calls to over‐
301 head microseconds. This is useful for overriding
302 the default heuristic for guessing how much time is
303 spent in mere measuring when timing system calls
304 using the -c option. The accuracy of the heuristic
305 can be gauged by timing a given program run without
306 tracing (using time(1)) and comparing the accumu‐
307 lated system call time to the total produced using
308 -c.
309
310 -p pid Attach to the process with the process ID pid and
311 begin tracing. The trace may be terminated at any
312 time by a keyboard interrupt signal (CTRL-C).
313 strace will respond by detaching itself from the
314 traced process(es) leaving it (them) to continue
315 running. Multiple -p options can be used to attach
316 to up to 32 processes in addition to command (which
317 is optional if at least one -p option is given).
318
319 -s strsize Specify the maximum string size to print (the
320 default is 32). Note that filenames are not consid‐
321 ered strings and are always printed in full.
322
323 -S sortby Sort the output of the histogram printed by the -c
324 option by the specified criterion. Legal values are
325 time, calls, name, and nothing (default time).
326
327 -u username Run command with the user ID, group ID, and supple‐
328 mentary groups of username. This option is only
329 useful when running as root and enables the correct
330 execution of setuid and/or setgid binaries. Unless
331 this option is used setuid and setgid programs are
332 executed without effective privileges.
333
334 -E var=val Run command with var=val in its list of environment
335 variables.
336
337 -E var Remove var from the inherited list of environment
338 variables before passing it on to the command.
339
341 If strace is installed setuid to root then the invoking user
342 will be able to attach to and trace processes owned by any user.
343 In addition setuid and setgid programs will be executed and
344 traced with the correct effective privileges. Since only users
345 trusted with full root privileges should be allowed to do these
346 things, it only makes sense to install strace as setuid to root
347 when the users who can execute it are restricted to those users
348 who have this trust. For example, it makes sense to install a
349 special version of strace with mode `rwsr-xr--', user root and
350 group trace, where members of the trace group are trusted users.
351 If you do use this feature, please remember to install a non-
352 setuid version of strace for ordinary lusers to use.
353
355 ltrace(1), time(1), ptrace(2), proc(5)
356
358 It is a pity that so much tracing clutter is produced by systems
359 employing shared libraries.
360
361 It is instructive to think about system call inputs and outputs
362 as data-flow across the user/kernel boundary. Because user-
363 space and kernel-space are separate and address-protected, it is
364 sometimes possible to make deductive inferences about process
365 behavior using inputs and outputs as propositions.
366
367 In some cases, a system call will differ from the documented
368 behavior or have a different name. For example, on System V-
369 derived systems the true time(2) system call does not take an
370 argument and the stat function is called xstat and takes an
371 extra leading argument. These discrepancies are normal but
372 idiosyncratic characteristics of the system call interface and
373 are accounted for by C library wrapper functions.
374
375 On some platforms a process that has a system call trace applied
376 to it with the -p option will receive a SIGSTOP. This signal
377 may interrupt a system call that is not restartable. This may
378 have an unpredictable effect on the process if the process takes
379 no action to restart the system call.
380
382 Programs that use the setuid bit do not have effective user ID
383 privileges while being traced.
384
385 A traced process ignores SIGSTOP except on SVR4 platforms.
386
387 A traced process which tries to block SIGTRAP will be sent a
388 SIGSTOP in an attempt to force continuation of tracing.
389
390 A traced process runs slowly.
391
392 Traced processes which are descended from command may be left
393 running after an interrupt signal (CTRL-C).
394
395 On Linux, exciting as it would be, tracing the init process is
396 forbidden.
397
398 The -i option is weakly supported.
399
401 strace The original strace was written by Paul Kranenburg for
402 SunOS and was inspired by its trace utility. The SunOS version
403 of strace was ported to Linux and enhanced by Branko Lankester,
404 who also wrote the Linux kernel support. Even though Paul
405 released strace 2.5 in 1992, Branko's work was based on Paul's
406 strace 1.5 release from 1991. In 1993, Rick Sladkey merged
407 strace 2.5 for SunOS and the second release of strace for Linux,
408 added many of the features of truss(1) from SVR4, and produced
409 an strace that worked on both platforms. In 1994 Rick ported
410 strace to SVR4 and Solaris and wrote the automatic configuration
411 support. In 1995 he ported strace to Irix and tired of writing
412 about himself in the third person.
413
415 Problems with strace should be reported via the Debian Bug
416 Tracking System, or to the strace mailing list at <strace-
417 devel@lists.sourceforge.net>.
418
419
420
421 2003-01-21 STRACE(1)