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 .\" Copyright (c) 1996-2017 The strace developers.
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. The name of the author may not be used to endorse or promote products
16 .\" derived from this software without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 .\" Macro IX is not defined in the groff macros
43 .TH STRACE 1 "2010-03-30"
45 strace \- trace system calls and signals
48 [\fB-CdffhikqrtttTvVxxy\fR]
55 [\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
57 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
58 \fIcommand\fR [\fIargs\fR]
66 [\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
68 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
69 \fIcommand\fR [\fIargs\fR]
71 .IX "strace command" "" "\fLstrace\fR command"
78 It intercepts and records the system calls which are called
79 by a process and the signals which are received by a process.
80 The name of each system call, its arguments and its return value
81 are printed on standard error or to the file specified with the
86 is a useful diagnostic, instructional, and debugging tool.
87 System administrators, diagnosticians and trouble-shooters will find
88 it invaluable for solving problems with
89 programs for which the source is not readily available since
90 they do not need to be recompiled in order to trace them.
91 Students, hackers and the overly-curious will find that
92 a great deal can be learned about a system and its system calls by
93 tracing even ordinary programs. And programmers will find that
94 since system calls and signals are events that happen at the user/kernel
95 interface, a close examination of this boundary is very
96 useful for bug isolation, sanity checking and
97 attempting to capture race conditions.
99 Each line in the trace contains the system call name, followed
100 by its arguments in parentheses and its return value.
101 An example from stracing the command "cat /dev/null" is:
103 open("/dev/null", O_RDONLY) = 3
105 Errors (typically a return value of \-1) have the errno symbol
106 and error string appended.
108 open("/foo/bar", O_RDONLY) = \-1 ENOENT (No such file or directory)
110 Signals are printed as signal symbol and decoded siginfo structure.
111 An excerpt from stracing and interrupting the command "sleep 666" is:
113 sigsuspend([] <unfinished ...>
114 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
115 +++ killed by SIGINT +++
117 If a system call is being executed and meanwhile another one is being called
118 from a different thread/process then
120 will try to preserve the order of those events and mark the ongoing call as
123 When the call returns it will be marked as
126 [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
127 [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
128 [pid 28772] <... select resumed> ) = 1 (in [3])
130 Interruption of a (restartable) system call by a signal delivery is processed
131 differently as kernel terminates the system call and also arranges its
132 immediate reexecution after the signal handler completes.
134 read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
136 rt_sigreturn(0xe) = 0
139 Arguments are printed in symbolic form with a passion.
140 This example shows the shell performing ">>xyzzy" output redirection:
142 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
144 Here the third argument of open is decoded by breaking down the
145 flag argument into its three bitwise-OR constituents and printing the
146 mode value in octal by tradition. Where traditional or native
147 usage differs from ANSI or POSIX, the latter forms are preferred.
150 output has proven to be more readable than the source.
152 Structure pointers are dereferenced and the members are displayed
153 as appropriate. In all cases arguments are formatted in the most C-like
155 For example, the essence of the command "ls \-l /dev/null" is captured as:
157 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
159 Notice how the 'struct stat' argument is dereferenced and how each member is
160 displayed symbolically. In particular, observe how the st_mode member
161 is carefully decoded into a bitwise-OR of symbolic and numeric values.
162 Also notice in this example that the first argument to lstat is an input
163 to the system call and the second argument is an output. Since output
164 arguments are not modified if the system call fails, arguments may not
165 always be dereferenced. For example, retrying the "ls \-l" example
166 with a non-existent file produces the following line:
168 lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
170 In this case the porch light is on but nobody is home.
172 Character pointers are dereferenced and printed as C strings.
173 Non-printing characters in strings are normally represented by
174 ordinary C escape codes.
177 (32 by default) bytes of strings are printed;
178 longer strings have an ellipsis appended following the closing quote.
179 Here is a line from "ls \-l" where the
181 library routine is reading the password file:
183 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
185 While structures are annotated using curly braces, simple pointers
186 and arrays are printed using square brackets with commas separating
187 elements. Here is an example from the command "id" on a system with
188 supplementary group ids:
190 getgroups(32, [100, 0]) = 2
192 On the other hand, bit-sets are also shown using square brackets
193 but set elements are separated only by a space. Here is the shell
194 preparing to execute an external command:
196 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
198 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
199 In some cases the bit-set is so full that printing out the unset
200 elements is more valuable. In that case, the bit-set is prefixed by
203 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
205 Here the second argument represents the full set of all signals.
210 Align return values in a specific column (default column 40).
213 Print the instruction pointer at the time of the system call.
216 Print the execution stack trace of the traced processes after each system call (experimental).
217 This option is available only if
219 is built with libunwind.
222 Write the trace output to the file
224 rather than to stderr.
230 If the argument begins with '|' or with '!' then the rest of the
231 argument is treated as a command and all output is piped to it.
232 This is convenient for piping the debugging output to a program
233 without affecting the redirections of executed programs.
236 Suppress messages about attaching, detaching etc. This happens
237 automatically when output is redirected to a file and the command
238 is run directly instead of attaching.
241 If given twice, suppress messages about process exit status.
244 Print a relative timestamp upon entry to each system call. This
245 records the time difference between the beginning of successive
249 Specify the maximum string size to print (the default is 32). Note
250 that filenames are not considered strings and are always printed in
254 Prefix each line of the trace with the time of day.
257 If given twice, the time printed will include the microseconds.
260 If given thrice, the time printed will include the microseconds
261 and the leading portion will be printed as the number
262 of seconds since the epoch.
265 Show the time spent in system calls. This records the time
266 difference between the beginning and the end of each system call.
269 Print all non-ASCII strings in hexadecimal string format.
272 Print all strings in hexadecimal string format.
275 Print paths associated with file descriptor arguments.
278 Print protocol specific information associated with socket file descriptors.
282 Count time, calls, and errors for each system call and report a summary on
283 program exit. On Linux, this attempts to show system time (CPU time spent
284 running in the kernel) independent of wall clock time. If
290 , only aggregate totals for all traced processes are kept.
295 but also print regular output while processes are running.
298 Set the overhead for tracing system calls to
301 This is useful for overriding the default heuristic for guessing
302 how much time is spent in mere measuring when timing system calls using
305 option. The accuracy of the heuristic can be gauged by timing a given
306 program run without tracing (using
308 and comparing the accumulated
309 system call time to the total produced using
313 Sort the output of the histogram printed by the
315 option by the specified criterion. Legal values are
325 Summarise the time difference between the beginning and end of
326 each system call. The default is to summarise the system time.
330 A qualifying expression which modifies which events to trace
331 or how to trace them. The format of the expression is:
334 [\,\fIqualifier\/\fB=\fR][\fB!\fR][\fB?\fR]\,\fIvalue1\/\fR[\fB,\fR[\fB?\fR]\,\fIvalue2\/\fR]...
352 is a qualifier-dependent symbol or number. The default
355 Using an exclamation mark negates the set of values. For example,
358 .BR \-e "\ " trace = open
359 which in turn means trace only the
361 system call. By contrast,
362 .BR \-e "\ " trace "=!" open
363 means to trace every system call except
365 Question mark before the syscall qualification allows suppression of error
366 in case no syscalls matched the qualification provided.
367 In addition, the special values
371 have the obvious meanings.
373 Note that some shells use the exclamation point for history
374 expansion even inside quoted arguments. If so, you must escape
375 the exclamation point with a backslash.
377 \fB\-e\ trace\fR=\,\fIset\fR
378 Trace only the specified set of system calls. The
380 option is useful for determining which system calls might be useful
381 to trace. For example,
382 .BR trace = open,close,read,write
384 trace those four system calls. Be careful when making inferences
385 about the user/kernel boundary if only a subset of system calls
386 are being monitored. The default is
389 \fB\-e\ trace\fR=/\,\fIregex\fR
390 Trace only those system calls that match the
394 Extended Regular Expression syntax (see
397 .BR "\-e\ trace" = %file
399 .BR "\-e\ trace" = file " (deprecated)"
400 Trace all system calls which take a file name as an argument. You
401 can think of this as an abbreviation for
402 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
403 which is useful to seeing what files the process is referencing.
404 Furthermore, using the abbreviation will ensure that you don't
405 accidentally forget to include a call like
407 in the list. Betchya woulda forgot that one.
409 .BR "\-e\ trace" = %process
411 .BR "\-e\ trace" = process " (deprecated)"
412 Trace all system calls which involve process management. This
413 is useful for watching the fork, wait, and exec steps of a process.
415 .BR "\-e\ trace" = %network
417 .BR "\-e\ trace" = network " (deprecated)"
418 Trace all the network related system calls.
420 .BR "\-e\ trace" = %signal
422 .BR "\-e\ trace" = signal " (deprecated)"
423 Trace all signal related system calls.
425 .BR "\-e\ trace" = %ipc
427 .BR "\-e\ trace" = ipc " (deprecated)"
428 Trace all IPC related system calls.
430 .BR "\-e\ trace" = %desc
432 .BR "\-e\ trace" = desc " (deprecated)"
433 Trace all file descriptor related system calls.
435 .BR "\-e\ trace" = %memory
437 .BR "\-e\ trace" = memory " (deprecated)"
438 Trace all memory mapping related system calls.
440 .BR "\-e\ trace" = %stat
441 Trace stat syscall variants.
443 .BR "\-e\ trace" = %lstat
444 Trace lstat syscall variants.
446 .BR "\-e\ trace" = %fstat
447 Trace fstat and fstatat syscall variants.
449 .BR "\-e\ trace" = %%stat
450 Trace syscalls used for requesting file status (stat, lstat, fstat, fstatat,
451 statx, and their variants).
453 .BR "\-e\ trace" = %statfs
454 Trace statfs, statfs64, statvfs, osf_statfs, and osf_statfs64 system calls.
455 The same effect can be achieved with
456 .BR "\-e\ trace" = /^(.*_)?statv?fs
459 .BR "\-e\ trace" = %fstatfs
460 Trace fstatfs, fstatfs64, fstatvfs, osf_fstatfs, and osf_fstatfs64 system calls.
461 The same effect can be achieved with
462 .BR "\-e\ trace" = /fstatv?fs
465 .BR "\-e\ trace" = %%statfs
466 Trace syscalls related to file system statistics (statfs-like, fstatfs-like,
467 and ustat). The same effect can be achieved with
468 .BR "\-e\ trace" = /statv?fs|fsstat|ustat
471 \fB\-e\ abbrev\fR=\,\fIset\fR
472 Abbreviate the output from printing each member of large structures.
477 option has the effect of
480 \fB\-e\ verbose\fR=\,\fIset\fR
481 Dereference structures for the specified set of system calls. The
485 \fB\-e\ raw\fR=\,\fIset\fR
486 Print raw, undecoded arguments for the specified set of system calls.
487 This option has the effect of causing all arguments to be printed
488 in hexadecimal. This is mostly useful if you don't trust the
489 decoding or you need to know the actual numeric value of an
492 \fB\-e\ signal\fR=\,\fIset\fR
493 Trace only the specified subset of signals. The default is
499 causes SIGIO signals not to be traced.
501 \fB\-e\ read\fR=\,\fIset\fR
502 Perform a full hexadecimal and ASCII dump of all the data read from
503 file descriptors listed in the specified set. For example, to see
504 all input activity on file descriptors
509 \fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
510 Note that this is independent from the normal tracing of the
512 system call which is controlled by the option
513 .BR -e "\ " trace = read .
515 \fB\-e\ write\fR=\,\fIset\fR
516 Perform a full hexadecimal and ASCII dump of all the data written to
517 file descriptors listed in the specified set. For example, to see
518 all output activity on file descriptors
523 \fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
524 Note that this is independent from the normal tracing of the
526 system call which is controlled by the option
527 .BR -e "\ " trace = write .
529 \fB\-e\ inject\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR|:\fBretval\fR=\,\fIvalue\/\fR][:\fBsignal\fR=\,\fIsig\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
530 Perform syscall tampering for the specified set of syscalls.
537 options has to be specified.
541 are mutually exclusive.
543 If :\fBerror\fR=\,\fIerrno\/\fR option is specified,
544 a fault is injected into a syscall invocation:
545 the syscall number is replaced by -1 which corresponds to an invalid syscall,
546 and the error code is specified using a symbolic
550 or a numeric value within 1..4095 range.
552 If :\fBretval\fR=\,\fIvalue\/\fR option is specified,
553 success injection is performed: the syscall number is replaced by -1,
554 but a bogus success value is returned to the callee.
556 If :\fBsignal\fR=\,\fIsig\/\fR option is specified with either a symbolic value
559 or a numeric value within 1..\fBSIGRTMAX\fR range,
560 that signal is delivered on entering every syscall specified by the
563 If :\fBsignal\fR=\,\fIsig\/\fR option is specified without
564 :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR options,
567 is delivered without a syscall fault injection.
568 Conversely, :\fBerror\fR=\,\fIerrno\/\fR or
569 :\fBretval\fR=\,\fIvalue\/\fR option without
570 :\fBsignal\fR=\,\fIsig\/\fR option injects a fault without delivering a signal.
572 If both :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR
573 and :\fBsignal\fR=\,\fIsig\/\fR options are specified, then both
574 a fault or success is injected and a signal is delivered.
576 Unless a :\fBwhen\fR=\,\fIexpr\fR subexpression is specified,
577 an injection is being made into every invocation of each syscall from the
580 The format of the subexpression is one of the following:
585 For every syscall from the
587 perform an injection for the syscall invocation number
594 For every syscall from the
596 perform injections for the syscall invocation number
598 and all subsequent invocations.
601 \fIfirst\/\fB+\fIstep\fR
603 For every syscall from the
605 perform injections for syscall invocations number
608 .IR first + step + step ,
613 For example, to fail each third and subsequent chdir syscalls with
616 \fB\-e\ inject\fR=\,\fIchdir\/\fR:\fBerror\fR=\,\fIENOENT\/\fR:\fBwhen\fR=\,\fI3\/\fB+\fR.
618 The valid range for numbers
624 An injection expression can contain only one
629 If an injection expression contains multiple
631 specifications, the last one takes precedence.
633 Accounting of syscalls that are subject to injection
634 is done per syscall and per tracee.
636 Specification of syscall injection can be combined
637 with other syscall filtering options, for example,
638 \fB\-P \fI/dev/urandom \fB\-e inject\fR=\,\fIfile\/\fR:\fBerror\fR=\,\fIENOENT\fR.
641 \fB\-e\ fault\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
642 Perform syscall fault injection for the specified set of syscalls.
644 This is equivalent to more generic
645 \fB\-e\ inject\fR= expression with default value of
652 Trace only system calls accessing
656 options can be used to specify several paths.
659 Print unabbreviated versions of environment, stat, termios, etc.
660 calls. These structures are very common in calls and so the default
661 behavior displays a reasonable subset of structure members. Use
662 this option to get all of the gory details.
666 If specified syscall is reached, detach from traced process.
669 syscall is supported. This option is useful if you want to trace
670 multi-threaded process and therefore require -f, but don't want
671 to trace its (potentially very complex) children.
674 Run tracer process as a detached grandchild, not as parent of the
675 tracee. This reduces the visible effect of
677 by keeping the tracee a direct child of the calling process.
680 Trace child processes as they are created by currently traced
681 processes as a result of the
686 system calls. Note that
690 will attach all threads of process PID if it is multi-threaded,
691 not only thread with thread_id = PID.
697 option is in effect, each processes trace is written to
699 where pid is the numeric process id of each process.
700 This is incompatible with
702 since no per-process counts are kept.
704 .BI "\-I " interruptible
705 When strace can be interrupted by signals (such as pressing ^C).
706 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
707 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
708 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
709 strace -o FILE PROG not stop on ^Z).
712 \fB\-E\ \fIvar\fR=\,\fIval\fR
715 in its list of environment variables.
720 from the inherited list of environment variables before passing it on to
724 Attach to the process with the process
728 The trace may be terminated
729 at any time by a keyboard interrupt signal (\c
732 will respond by detaching itself from the traced process(es)
733 leaving it (them) to continue running.
736 options can be used to attach to many processes in addition to
738 (which is optional if at least one
742 "`pidof PROG`" syntax is supported.
745 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
746 supplementary groups of
748 This option is only useful when running as root and enables the
749 correct execution of setuid and/or setgid binaries.
750 Unless this option is used setuid and setgid programs are executed
751 without effective privileges.
755 Show some debugging output of
757 itself on the standard error.
760 This option is now obsolete and it has the same functionality as
764 Print the help summary.
767 Print the version number of
774 exits with the same exit status.
777 is terminated by a signal,
779 terminates itself with the same signal, so that
781 can be used as a wrapper process transparent to the invoking parent process.
782 Note that parent-child relationship (signal stop notifications,
783 getppid() value, etc) between traced process and its parent are not preserved
794 is zero unless no processes has been attached or there was an unexpected error
795 in doing the tracing.
796 .SH "SETUID INSTALLATION"
799 is installed setuid to root then the invoking user will be able to
800 attach to and trace processes owned by any user.
801 In addition setuid and setgid programs will be executed and traced
802 with the correct effective privileges.
803 Since only users trusted with full root privileges should be allowed
805 it only makes sense to install
807 as setuid to root when the users who can execute it are restricted
808 to those users who have this trust.
809 For example, it makes sense to install a special version of
811 with mode 'rwsr-xr--', user
817 group are trusted users.
818 If you do use this feature, please remember to install
819 a non-setuid version of
821 for ordinary lusers to use.
823 It is a pity that so much tracing clutter is produced by systems
824 employing shared libraries.
826 It is instructive to think about system call inputs and outputs
827 as data-flow across the user/kernel boundary. Because user-space
828 and kernel-space are separate and address-protected, it is
829 sometimes possible to make deductive inferences about process
830 behavior using inputs and outputs as propositions.
832 In some cases, a system call will differ from the documented behavior
833 or have a different name. For example, on System V-derived systems
836 system call does not take an argument and the
840 and takes an extra leading argument. These
841 discrepancies are normal but idiosyncratic characteristics of the
842 system call interface and are accounted for by C library wrapper
845 Some system calls have different names in different architectures and
846 personalities. In these cases, system call filtering and printing
847 uses the names that match corresponding
849 kernel macros of the tracee's architecture and personality.
850 There are two exceptions from this general rule:
851 .BR arm_fadvise64_64 (2)
853 .BR xtensa_fadvise64_64 (2)
854 Xtensa syscall are filtered and printed as
855 .BR fadvise64_64 (2).
857 On some platforms a process that is attached to with the
859 option may observe a spurious EINTR return from the current
860 system call that is not restartable. (Ideally, all system calls
861 should be restarted on strace attach, making the attach invisible
862 to the traced process, but a few system calls aren't.
863 Arguably, every instance of such behavior is a kernel bug.)
864 This may have an unpredictable effect on the process
865 if the process takes no action to restart the system call.
867 Programs that use the
872 privileges while being traced.
874 A traced process runs slowly.
876 Traced processes which are descended from
878 may be left running after an interrupt signal (\c
883 was written by Paul Kranenburg
884 for SunOS and was inspired by its trace utility.
887 was ported to Linux and enhanced
888 by Branko Lankester, who also wrote the Linux kernel support.
889 Even though Paul released
892 Branko's work was based on Paul's
894 1.5 release from 1991.
895 In 1993, Rick Sladkey merged
897 2.5 for SunOS and the second release of
899 for Linux, added many of the features of
901 from SVR4, and produced an
903 that worked on both platforms. In 1994 Rick ported
905 to SVR4 and Solaris and wrote the
906 automatic configuration support. In 1995 he ported
909 and tired of writing about himself in the third person.
913 should be reported to the
915 mailing list at <strace\-devel@lists.sourceforge.net>.