1 .\" 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.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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.
37 .TH STRACE 1 "2010-03-30"
39 strace \- trace system calls and signals
42 [\fB-CdffhikqrtttTvVxxy\fR]
49 [\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
51 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
52 \fIcommand\fR [\fIargs\fR]
60 [\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
62 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
63 \fIcommand\fR [\fIargs\fR]
65 .IX "strace command" "" "\fLstrace\fR command"
72 It intercepts and records the system calls which are called
73 by a process and the signals which are received by a process.
74 The name of each system call, its arguments and its return value
75 are printed on standard error or to the file specified with the
80 is a useful diagnostic, instructional, and debugging tool.
81 System administrators, diagnosticians and trouble-shooters will find
82 it invaluable for solving problems with
83 programs for which the source is not readily available since
84 they do not need to be recompiled in order to trace them.
85 Students, hackers and the overly-curious will find that
86 a great deal can be learned about a system and its system calls by
87 tracing even ordinary programs. And programmers will find that
88 since system calls and signals are events that happen at the user/kernel
89 interface, a close examination of this boundary is very
90 useful for bug isolation, sanity checking and
91 attempting to capture race conditions.
93 Each line in the trace contains the system call name, followed
94 by its arguments in parentheses and its return value.
95 An example from stracing the command "cat /dev/null" is:
97 open("/dev/null", O_RDONLY) = 3
99 Errors (typically a return value of \-1) have the errno symbol
100 and error string appended.
102 open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
104 Signals are printed as signal symbol and decoded siginfo structure.
105 An excerpt from stracing and interrupting the command "sleep 666" is:
107 sigsuspend([] <unfinished ...>
108 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
109 +++ killed by SIGINT +++
111 If a system call is being executed and meanwhile another one is being called
112 from a different thread/process then
114 will try to preserve the order of those events and mark the ongoing call as
117 When the call returns it will be marked as
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])
124 Interruption of a (restartable) system call by a signal delivery is processed
125 differently as kernel terminates the system call and also arranges its
126 immediate reexecution after the signal handler completes.
128 read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
130 rt_sigreturn(0xe) = 0
133 Arguments are printed in symbolic form with a passion.
134 This example shows the shell performing ">>xyzzy" output redirection:
136 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
138 Here the third argument of open is decoded by breaking down the
139 flag argument into its three bitwise-OR constituents and printing the
140 mode value in octal by tradition. Where traditional or native
141 usage differs from ANSI or POSIX, the latter forms are preferred.
144 output has proven to be more readable than the source.
146 Structure pointers are dereferenced and the members are displayed
147 as appropriate. In all cases arguments are formatted in the most C-like
149 For example, the essence of the command "ls \-l /dev/null" is captured as:
151 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
153 Notice how the 'struct stat' argument is dereferenced and how each member is
154 displayed symbolically. In particular, observe how the st_mode member
155 is carefully decoded into a bitwise-OR of symbolic and numeric values.
156 Also notice in this example that the first argument to lstat is an input
157 to the system call and the second argument is an output. Since output
158 arguments are not modified if the system call fails, arguments may not
159 always be dereferenced. For example, retrying the "ls \-l" example
160 with a non-existent file produces the following line:
162 lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
164 In this case the porch light is on but nobody is home.
166 Character pointers are dereferenced and printed as C strings.
167 Non-printing characters in strings are normally represented by
168 ordinary C escape codes.
171 (32 by default) bytes of strings are printed;
172 longer strings have an ellipsis appended following the closing quote.
173 Here is a line from "ls \-l" where the
175 library routine is reading the password file:
177 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
179 While structures are annotated using curly braces, simple pointers
180 and arrays are printed using square brackets with commas separating
181 elements. Here is an example from the command "id" on a system with
182 supplementary group ids:
184 getgroups(32, [100, 0]) = 2
186 On the other hand, bit-sets are also shown using square brackets
187 but set elements are separated only by a space. Here is the shell
188 preparing to execute an external command:
190 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
192 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
193 In some cases the bit-set is so full that printing out the unset
194 elements is more valuable. In that case, the bit-set is prefixed by
197 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
199 Here the second argument represents the full set of all signals.
204 Count time, calls, and errors for each system call and report a summary on
205 program exit. On Linux, this attempts to show system time (CPU time spent
206 running in the kernel) independent of wall clock time. If
212 (below), only aggregate totals for all traced processes are kept.
217 but also print regular output while processes are running.
220 Run tracer process as a detached grandchild, not as parent of the
221 tracee. This reduces the visible effect of
223 by keeping the tracee a direct child of the calling process.
226 Show some debugging output of
228 itself on the standard error.
231 Trace child processes as they are created by currently traced
232 processes as a result of the
237 system calls. Note that
241 will attach all threads of process PID if it is multi-threaded,
242 not only thread with thread_id = PID.
248 option is in effect, each processes trace is written to
250 where pid is the numeric process id of each process.
251 This is incompatible with
253 since no per-process counts are kept.
256 This option is now obsolete and it has the same functionality as
260 Print the help summary.
263 Print the instruction pointer at the time of the system call.
266 Print the execution stack trace of the traced processes after each system call.
269 Suppress messages about attaching, detaching etc. This happens
270 automatically when output is redirected to a file and the command
271 is run directly instead of attaching.
274 If given twice, suppress messages about process exit status.
277 Print a relative timestamp upon entry to each system call. This
278 records the time difference between the beginning of successive
282 Prefix each line of the trace with the time of day.
285 If given twice, the time printed will include the microseconds.
288 If given thrice, the time printed will include the microseconds
289 and the leading portion will be printed as the number
290 of seconds since the epoch.
293 Show the time spent in system calls. This records the time
294 difference between the beginning and the end of each system call.
297 Summarise the time difference between the beginning and end of
298 each system call. The default is to summarise the system time.
301 Print unabbreviated versions of environment, stat, termios, etc.
302 calls. These structures are very common in calls and so the default
303 behavior displays a reasonable subset of structure members. Use
304 this option to get all of the gory details.
307 Print the version number of
311 Print all non-ASCII strings in hexadecimal string format.
314 Print all strings in hexadecimal string format.
317 Print paths associated with file descriptor arguments.
320 Align return values in a specific column (default column 40).
323 If specified syscall is reached, detach from traced process.
326 syscall is supported. This option is useful if you want to trace
327 multi-threaded process and therefore require -f, but don't want
328 to trace its (potentially very complex) children.
331 A qualifying expression which modifies which events to trace
332 or how to trace them. The format of the expression is:
335 [\fIqualifier\fB=\fR][\fB!\fR]\fIvalue1\fR[\fB,\fIvalue2\fR]...
351 is a qualifier-dependent symbol or number. The default
354 Using an exclamation mark negates the set of values. For example,
357 .BR \-e "\ " trace = open
358 which in turn means trace only the
360 system call. By contrast,
361 .BR \-e "\ " trace "=!" open
362 means to trace every system call except
364 In addition, the special values
368 have the obvious meanings.
370 Note that some shells use the exclamation point for history
371 expansion even inside quoted arguments. If so, you must escape
372 the exclamation point with a backslash.
374 \fB\-e\ trace\fR=\fIset\fR
375 Trace only the specified set of system calls. The
377 option is useful for determining which system calls might be useful
378 to trace. For example,
379 .BR trace = open,close,read,write
381 trace those four system calls. Be careful when making inferences
382 about the user/kernel boundary if only a subset of system calls
383 are being monitored. The default is
386 .BR "\-e\ trace" = file
387 Trace all system calls which take a file name as an argument. You
388 can think of this as an abbreviation for
389 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
390 which is useful to seeing what files the process is referencing.
391 Furthermore, using the abbreviation will ensure that you don't
392 accidentally forget to include a call like
394 in the list. Betchya woulda forgot that one.
396 .BR "\-e\ trace" = process
397 Trace all system calls which involve process management. This
398 is useful for watching the fork, wait, and exec steps of a process.
400 .BR "\-e\ trace" = network
401 Trace all the network related system calls.
403 .BR "\-e\ trace" = signal
404 Trace all signal related system calls.
406 .BR "\-e\ trace" = ipc
407 Trace all IPC related system calls.
409 .BR "\-e\ trace" = desc
410 Trace all file descriptor related system calls.
412 .BR "\-e\ trace" = memory
413 Trace all memory mapping related system calls.
415 \fB\-e\ abbrev\fR=\fIset\fR
416 Abbreviate the output from printing each member of large structures.
421 option has the effect of
424 \fB\-e\ verbose\fR=\fIset\fR
425 Dereference structures for the specified set of system calls. The
429 \fB\-e\ raw\fR=\fIset\fR
430 Print raw, undecoded arguments for the specified set of system calls.
431 This option has the effect of causing all arguments to be printed
432 in hexadecimal. This is mostly useful if you don't trust the
433 decoding or you need to know the actual numeric value of an
436 \fB\-e\ signal\fR=\fIset\fR
437 Trace only the specified subset of signals. The default is
443 causes SIGIO signals not to be traced.
445 \fB\-e\ read\fR=\fIset\fR
446 Perform a full hexadecimal and ASCII dump of all the data read from
447 file descriptors listed in the specified set. For example, to see
448 all input activity on file descriptors
453 \fB\-e\ read\fR=\fI3\fR,\fI5\fR.
454 Note that this is independent from the normal tracing of the
456 system call which is controlled by the option
457 .BR -e "\ " trace = read .
459 \fB\-e\ write\fR=\fIset\fR
460 Perform a full hexadecimal and ASCII dump of all the data written to
461 file descriptors listed in the specified set. For example, to see
462 all output activity on file descriptors
467 \fB\-e\ write\fR=\fI3\fR,\fI5\fR.
468 Note that this is independent from the normal tracing of the
470 system call which is controlled by the option
471 .BR -e "\ " trace = write .
473 .BI "\-I " interruptible
474 When strace can be interrupted by signals (such as pressing ^C).
475 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
476 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
477 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
478 strace -o FILE PROG not stop on ^Z).
481 Write the trace output to the file
483 rather than to stderr.
489 If the argument begins with '|' or with '!' then the rest of the
490 argument is treated as a command and all output is piped to it.
491 This is convenient for piping the debugging output to a program
492 without affecting the redirections of executed programs.
495 Set the overhead for tracing system calls to
498 This is useful for overriding the default heuristic for guessing
499 how much time is spent in mere measuring when timing system calls using
502 option. The accuracy of the heuristic can be gauged by timing a given
503 program run without tracing (using
505 and comparing the accumulated
506 system call time to the total produced using
510 Attach to the process with the process
514 The trace may be terminated
515 at any time by a keyboard interrupt signal (\c
518 will respond by detaching itself from the traced process(es)
519 leaving it (them) to continue running.
522 options can be used to attach to many processes.
523 -p "`pidof PROG`" syntax is supported.
526 Trace only system calls accessing
530 options can be used to specify several paths.
533 Specify the maximum string size to print (the default is 32). Note
534 that filenames are not considered strings and are always printed in
538 Sort the output of the histogram printed by the
540 option by the specified criterion. Legal values are
550 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
551 supplementary groups of
553 This option is only useful when running as root and enables the
554 correct execution of setuid and/or setgid binaries.
555 Unless this option is used setuid and setgid programs are executed
556 without effective privileges.
558 \fB\-E\ \fIvar\fR=\fIval\fR
561 in its list of environment variables.
566 from the inherited list of environment variables before passing it on to
573 exits with the same exit status.
576 is terminated by a signal,
578 terminates itself with the same signal, so that
580 can be used as a wrapper process transparent to the invoking parent process.
581 Note that parent-child relationship (signal stop notifications,
582 getppid() value, etc) between traced process and its parent are not preserved
591 is zero unless there was an unexpected error in doing the tracing.
592 .SH "SETUID INSTALLATION"
595 is installed setuid to root then the invoking user will be able to
596 attach to and trace processes owned by any user.
597 In addition setuid and setgid programs will be executed and traced
598 with the correct effective privileges.
599 Since only users trusted with full root privileges should be allowed
601 it only makes sense to install
603 as setuid to root when the users who can execute it are restricted
604 to those users who have this trust.
605 For example, it makes sense to install a special version of
607 with mode 'rwsr-xr--', user
613 group are trusted users.
614 If you do use this feature, please remember to install
615 a non-setuid version of
617 for ordinary lusers to use.
624 It is a pity that so much tracing clutter is produced by systems
625 employing shared libraries.
627 It is instructive to think about system call inputs and outputs
628 as data-flow across the user/kernel boundary. Because user-space
629 and kernel-space are separate and address-protected, it is
630 sometimes possible to make deductive inferences about process
631 behavior using inputs and outputs as propositions.
633 In some cases, a system call will differ from the documented behavior
634 or have a different name. For example, on System V-derived systems
637 system call does not take an argument and the
641 and takes an extra leading argument. These
642 discrepancies are normal but idiosyncratic characteristics of the
643 system call interface and are accounted for by C library wrapper
646 On some platforms a process that is attached to with the
648 option may observe a spurious EINTR return from the current
649 system call that is not restartable. (Ideally, all system calls
650 should be restarted on strace attach, making the attach invisible
651 to the traced process, but a few system calls aren't.
652 Arguably, every instance of such behavior is a kernel bug.)
653 This may have an unpredictable effect on the process
654 if the process takes no action to restart the system call.
656 Programs that use the
661 privileges while being traced.
663 A traced process runs slowly.
665 Traced processes which are descended from
667 may be left running after an interrupt signal (\c
672 option is weakly supported.
676 was written by Paul Kranenburg
677 for SunOS and was inspired by its trace utility.
680 was ported to Linux and enhanced
681 by Branko Lankester, who also wrote the Linux kernel support.
682 Even though Paul released
685 Branko's work was based on Paul's
687 1.5 release from 1991.
688 In 1993, Rick Sladkey merged
690 2.5 for SunOS and the second release of
692 for Linux, added many of the features of
694 from SVR4, and produced an
696 that worked on both platforms. In 1994 Rick ported
698 to SVR4 and Solaris and wrote the
699 automatic configuration support. In 1995 he ported
702 and tired of writing about himself in the third person.
706 should be reported to the
708 mailing list at <strace\-devel@lists.sourceforge.net>.