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.
40 .\" Like .OP, but with ellipsis at the end in order to signify that option
41 .\" can be provided multiple times. Based on .OP definition in groff's
45 . RI "[\fB\\$1\fP" "\ \\$2" "]...\&"
47 . RB "[" "\\$1" "]...\&"
52 . RI "\fB\\$1\fP" "\ \\$2"
56 .TH STRACE 1 "@MANPAGE_DATE@" "strace @VERSION@"
58 strace \- trace system calls and signals
61 .OP \-CdffhikqrtttTvVxxy
74 .OM \-E var\fR[=\fIval\fR]
76 .IR command " [" args ]
93 .OM \-E var\fR[=\fIval\fR]
95 .IR command " [" args ]
100 .IX "strace command" "" "\fLstrace\fR command"
107 It intercepts and records the system calls which are called
108 by a process and the signals which are received by a process.
109 The name of each system call, its arguments and its return value
110 are printed on standard error or to the file specified with the
115 is a useful diagnostic, instructional, and debugging tool.
116 System administrators, diagnosticians and trouble-shooters will find
117 it invaluable for solving problems with
118 programs for which the source is not readily available since
119 they do not need to be recompiled in order to trace them.
120 Students, hackers and the overly-curious will find that
121 a great deal can be learned about a system and its system calls by
122 tracing even ordinary programs. And programmers will find that
123 since system calls and signals are events that happen at the user/kernel
124 interface, a close examination of this boundary is very
125 useful for bug isolation, sanity checking and
126 attempting to capture race conditions.
128 Each line in the trace contains the system call name, followed
129 by its arguments in parentheses and its return value.
130 An example from stracing the command "cat /dev/null" is:
132 open("/dev/null", O_RDONLY) = 3
134 Errors (typically a return value of \-1) have the errno symbol
135 and error string appended.
137 open("/foo/bar", O_RDONLY) = \-1 ENOENT (No such file or directory)
139 Signals are printed as signal symbol and decoded siginfo structure.
140 An excerpt from stracing and interrupting the command "sleep 666" is:
142 sigsuspend([] <unfinished ...>
143 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
144 +++ killed by SIGINT +++
146 If a system call is being executed and meanwhile another one is being called
147 from a different thread/process then
149 will try to preserve the order of those events and mark the ongoing call as
152 When the call returns it will be marked as
155 [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
156 [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
157 [pid 28772] <... select resumed> ) = 1 (in [3])
159 Interruption of a (restartable) system call by a signal delivery is processed
160 differently as kernel terminates the system call and also arranges its
161 immediate reexecution after the signal handler completes.
163 read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
165 rt_sigreturn(0xe) = 0
168 Arguments are printed in symbolic form with a passion.
169 This example shows the shell performing ">>xyzzy" output redirection:
171 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
173 Here the third argument of open is decoded by breaking down the
174 flag argument into its three bitwise-OR constituents and printing the
175 mode value in octal by tradition. Where traditional or native
176 usage differs from ANSI or POSIX, the latter forms are preferred.
179 output has proven to be more readable than the source.
181 Structure pointers are dereferenced and the members are displayed
182 as appropriate. In all cases arguments are formatted in the most C-like
184 For example, the essence of the command "ls \-l /dev/null" is captured as:
186 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
188 Notice how the 'struct stat' argument is dereferenced and how each member is
189 displayed symbolically. In particular, observe how the st_mode member
190 is carefully decoded into a bitwise-OR of symbolic and numeric values.
191 Also notice in this example that the first argument to lstat is an input
192 to the system call and the second argument is an output. Since output
193 arguments are not modified if the system call fails, arguments may not
194 always be dereferenced. For example, retrying the "ls \-l" example
195 with a non-existent file produces the following line:
197 lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
199 In this case the porch light is on but nobody is home.
201 Character pointers are dereferenced and printed as C strings.
202 Non-printing characters in strings are normally represented by
203 ordinary C escape codes.
206 (32 by default) bytes of strings are printed;
207 longer strings have an ellipsis appended following the closing quote.
208 Here is a line from "ls \-l" where the
210 library routine is reading the password file:
212 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
214 While structures are annotated using curly braces, simple pointers
215 and arrays are printed using square brackets with commas separating
216 elements. Here is an example from the command "id" on a system with
217 supplementary group ids:
219 getgroups(32, [100, 0]) = 2
221 On the other hand, bit-sets are also shown using square brackets
222 but set elements are separated only by a space. Here is the shell
223 preparing to execute an external command:
225 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
227 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
228 In some cases the bit-set is so full that printing out the unset
229 elements is more valuable. In that case, the bit-set is prefixed by
232 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
234 Here the second argument represents the full set of all signals.
239 Align return values in a specific column (default column 40).
242 Print the instruction pointer at the time of the system call.
245 Print the execution stack trace of the traced processes after each system call (experimental).
246 This option is available only if
248 is built with libunwind.
251 Write the trace output to the file
253 rather than to stderr.
259 If the argument begins with '|' or with '!' then the rest of the
260 argument is treated as a command and all output is piped to it.
261 This is convenient for piping the debugging output to a program
262 without affecting the redirections of executed programs.
265 Suppress messages about attaching, detaching etc. This happens
266 automatically when output is redirected to a file and the command
267 is run directly instead of attaching.
270 If given twice, suppress messages about process exit status.
273 Print a relative timestamp upon entry to each system call. This
274 records the time difference between the beginning of successive
278 Specify the maximum string size to print (the default is 32). Note
279 that filenames are not considered strings and are always printed in
283 Prefix each line of the trace with the time of day.
286 If given twice, the time printed will include the microseconds.
289 If given thrice, the time printed will include the microseconds
290 and the leading portion will be printed as the number
291 of seconds since the epoch.
294 Show the time spent in system calls. This records the time
295 difference between the beginning and the end of each system call.
298 Print all non-ASCII strings in hexadecimal string format.
301 Print all strings in hexadecimal string format.
304 Print paths associated with file descriptor arguments.
307 Print protocol specific information associated with socket file descriptors.
311 Count time, calls, and errors for each system call and report a summary on
312 program exit. On Linux, this attempts to show system time (CPU time spent
313 running in the kernel) independent of wall clock time. If
319 , only aggregate totals for all traced processes are kept.
324 but also print regular output while processes are running.
327 Set the overhead for tracing system calls to
330 This is useful for overriding the default heuristic for guessing
331 how much time is spent in mere measuring when timing system calls using
334 option. The accuracy of the heuristic can be gauged by timing a given
335 program run without tracing (using
337 and comparing the accumulated
338 system call time to the total produced using
342 Sort the output of the histogram printed by the
344 option by the specified criterion. Legal values are
354 Summarise the time difference between the beginning and end of
355 each system call. The default is to summarise the system time.
359 A qualifying expression which modifies which events to trace
360 or how to trace them. The format of the expression is:
363 [\,\fIqualifier\/\fB=\fR][\fB!\fR][\fB?\fR]\,\fIvalue1\/\fR[\fB,\fR[\fB?\fR]\,\fIvalue2\/\fR]...
381 is a qualifier-dependent symbol or number. The default
384 Using an exclamation mark negates the set of values. For example,
387 .BR \-e "\ " trace = open
388 which in turn means trace only the
390 system call. By contrast,
391 .BR \-e "\ " trace "=!" open
392 means to trace every system call except
394 Question mark before the syscall qualification allows suppression of error
395 in case no syscalls matched the qualification provided.
396 In addition, the special values
400 have the obvious meanings.
402 Note that some shells use the exclamation point for history
403 expansion even inside quoted arguments. If so, you must escape
404 the exclamation point with a backslash.
406 \fB\-e\ trace\fR=\,\fIset\fR
407 Trace only the specified set of system calls. The
409 option is useful for determining which system calls might be useful
410 to trace. For example,
411 .BR trace = open,close,read,write
413 trace those four system calls. Be careful when making inferences
414 about the user/kernel boundary if only a subset of system calls
415 are being monitored. The default is
418 \fB\-e\ trace\fR=/\,\fIregex\fR
419 Trace only those system calls that match the
423 Extended Regular Expression syntax (see
426 .BR "\-e\ trace" = %file
428 .BR "\-e\ trace" = file " (deprecated)"
429 Trace all system calls which take a file name as an argument. You
430 can think of this as an abbreviation for
431 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
432 which is useful to seeing what files the process is referencing.
433 Furthermore, using the abbreviation will ensure that you don't
434 accidentally forget to include a call like
436 in the list. Betchya woulda forgot that one.
438 .BR "\-e\ trace" = %process
440 .BR "\-e\ trace" = process " (deprecated)"
441 Trace all system calls which involve process management. This
442 is useful for watching the fork, wait, and exec steps of a process.
444 .BR "\-e\ trace" = %network
446 .BR "\-e\ trace" = network " (deprecated)"
447 Trace all the network related system calls.
449 .BR "\-e\ trace" = %signal
451 .BR "\-e\ trace" = signal " (deprecated)"
452 Trace all signal related system calls.
454 .BR "\-e\ trace" = %ipc
456 .BR "\-e\ trace" = ipc " (deprecated)"
457 Trace all IPC related system calls.
459 .BR "\-e\ trace" = %desc
461 .BR "\-e\ trace" = desc " (deprecated)"
462 Trace all file descriptor related system calls.
464 .BR "\-e\ trace" = %memory
466 .BR "\-e\ trace" = memory " (deprecated)"
467 Trace all memory mapping related system calls.
469 .BR "\-e\ trace" = %stat
470 Trace stat syscall variants.
472 .BR "\-e\ trace" = %lstat
473 Trace lstat syscall variants.
475 .BR "\-e\ trace" = %fstat
476 Trace fstat and fstatat syscall variants.
478 .BR "\-e\ trace" = %%stat
479 Trace syscalls used for requesting file status (stat, lstat, fstat, fstatat,
480 statx, and their variants).
482 .BR "\-e\ trace" = %statfs
483 Trace statfs, statfs64, statvfs, osf_statfs, and osf_statfs64 system calls.
484 The same effect can be achieved with
485 .BR "\-e\ trace" = /^(.*_)?statv?fs
488 .BR "\-e\ trace" = %fstatfs
489 Trace fstatfs, fstatfs64, fstatvfs, osf_fstatfs, and osf_fstatfs64 system calls.
490 The same effect can be achieved with
491 .BR "\-e\ trace" = /fstatv?fs
494 .BR "\-e\ trace" = %%statfs
495 Trace syscalls related to file system statistics (statfs-like, fstatfs-like,
496 and ustat). The same effect can be achieved with
497 .BR "\-e\ trace" = /statv?fs|fsstat|ustat
500 \fB\-e\ abbrev\fR=\,\fIset\fR
501 Abbreviate the output from printing each member of large structures.
506 option has the effect of
509 \fB\-e\ verbose\fR=\,\fIset\fR
510 Dereference structures for the specified set of system calls. The
514 \fB\-e\ raw\fR=\,\fIset\fR
515 Print raw, undecoded arguments for the specified set of system calls.
516 This option has the effect of causing all arguments to be printed
517 in hexadecimal. This is mostly useful if you don't trust the
518 decoding or you need to know the actual numeric value of an
521 \fB\-e\ signal\fR=\,\fIset\fR
522 Trace only the specified subset of signals. The default is
528 causes SIGIO signals not to be traced.
530 \fB\-e\ read\fR=\,\fIset\fR
531 Perform a full hexadecimal and ASCII dump of all the data read from
532 file descriptors listed in the specified set. For example, to see
533 all input activity on file descriptors
538 \fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
539 Note that this is independent from the normal tracing of the
541 system call which is controlled by the option
542 .BR -e "\ " trace = read .
544 \fB\-e\ write\fR=\,\fIset\fR
545 Perform a full hexadecimal and ASCII dump of all the data written to
546 file descriptors listed in the specified set. For example, to see
547 all output activity on file descriptors
552 \fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
553 Note that this is independent from the normal tracing of the
555 system call which is controlled by the option
556 .BR -e "\ " trace = write .
558 \fB\-e\ inject\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR|:\fBretval\fR=\,\fIvalue\/\fR][:\fBsignal\fR=\,\fIsig\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
559 Perform syscall tampering for the specified set of syscalls.
566 options has to be specified.
570 are mutually exclusive.
572 If :\fBerror\fR=\,\fIerrno\/\fR option is specified,
573 a fault is injected into a syscall invocation:
574 the syscall number is replaced by -1 which corresponds to an invalid syscall,
575 and the error code is specified using a symbolic
579 or a numeric value within 1..4095 range.
581 If :\fBretval\fR=\,\fIvalue\/\fR option is specified,
582 success injection is performed: the syscall number is replaced by -1,
583 but a bogus success value is returned to the callee.
585 If :\fBsignal\fR=\,\fIsig\/\fR option is specified with either a symbolic value
588 or a numeric value within 1..\fBSIGRTMAX\fR range,
589 that signal is delivered on entering every syscall specified by the
592 If :\fBsignal\fR=\,\fIsig\/\fR option is specified without
593 :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR options,
596 is delivered without a syscall fault injection.
597 Conversely, :\fBerror\fR=\,\fIerrno\/\fR or
598 :\fBretval\fR=\,\fIvalue\/\fR option without
599 :\fBsignal\fR=\,\fIsig\/\fR option injects a fault without delivering a signal.
601 If both :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR
602 and :\fBsignal\fR=\,\fIsig\/\fR options are specified, then both
603 a fault or success is injected and a signal is delivered.
605 Unless a :\fBwhen\fR=\,\fIexpr\fR subexpression is specified,
606 an injection is being made into every invocation of each syscall from the
609 The format of the subexpression is one of the following:
614 For every syscall from the
616 perform an injection for the syscall invocation number
623 For every syscall from the
625 perform injections for the syscall invocation number
627 and all subsequent invocations.
630 \fIfirst\/\fB+\fIstep\fR
632 For every syscall from the
634 perform injections for syscall invocations number
637 .IR first + step + step ,
642 For example, to fail each third and subsequent chdir syscalls with
645 \fB\-e\ inject\fR=\,\fIchdir\/\fR:\fBerror\fR=\,\fIENOENT\/\fR:\fBwhen\fR=\,\fI3\/\fB+\fR.
647 The valid range for numbers
653 An injection expression can contain only one
657 specification, and only one
659 specification. If an injection expression contains multiple
661 specifications, the last one takes precedence.
663 Accounting of syscalls that are subject to injection
664 is done per syscall and per tracee.
666 Specification of syscall injection can be combined
667 with other syscall filtering options, for example,
668 \fB\-P \fI/dev/urandom \fB\-e inject\fR=\,\fIfile\/\fR:\fBerror\fR=\,\fIENOENT\fR.
671 \fB\-e\ fault\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
672 Perform syscall fault injection for the specified set of syscalls.
674 This is equivalent to more generic
675 \fB\-e\ inject\fR= expression with default value of
682 Trace only system calls accessing
686 options can be used to specify several paths.
689 Print unabbreviated versions of environment, stat, termios, etc.
690 calls. These structures are very common in calls and so the default
691 behavior displays a reasonable subset of structure members. Use
692 this option to get all of the gory details.
696 If specified syscall is reached, detach from traced process.
699 syscall is supported. This option is useful if you want to trace
700 multi-threaded process and therefore require -f, but don't want
701 to trace its (potentially very complex) children.
704 Run tracer process as a detached grandchild, not as parent of the
705 tracee. This reduces the visible effect of
707 by keeping the tracee a direct child of the calling process.
710 Trace child processes as they are created by currently traced
711 processes as a result of the
716 system calls. Note that
720 will attach all threads of process PID if it is multi-threaded,
721 not only thread with thread_id = PID.
727 option is in effect, each processes trace is written to
729 where pid is the numeric process id of each process.
730 This is incompatible with
732 since no per-process counts are kept.
734 One might want to consider using
735 .BR strace-log-merge (1)
736 to obtain a combined strace log view.
738 .BI "\-I " interruptible
739 When strace can be interrupted by signals (such as pressing ^C).
740 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
741 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
742 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
743 strace -o FILE PROG not stop on ^Z).
746 \fB\-E\ \fIvar\fR=\,\fIval\fR
749 in its list of environment variables.
754 from the inherited list of environment variables before passing it on to
758 Attach to the process with the process
762 The trace may be terminated
763 at any time by a keyboard interrupt signal (\c
766 will respond by detaching itself from the traced process(es)
767 leaving it (them) to continue running.
770 options can be used to attach to many processes in addition to
772 (which is optional if at least one
776 "`pidof PROG`" syntax is supported.
779 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
780 supplementary groups of
782 This option is only useful when running as root and enables the
783 correct execution of setuid and/or setgid binaries.
784 Unless this option is used setuid and setgid programs are executed
785 without effective privileges.
789 Show some debugging output of
791 itself on the standard error.
794 This option is deprecated. It is retained for backward compatibility only
795 and may be removed in future releases.
796 Usage of multiple instances of
798 option is still equivalent to a single
800 and it is ignored at all if used along with one or more instances of
805 Print the help summary.
808 Print the version number of
815 exits with the same exit status.
818 is terminated by a signal,
820 terminates itself with the same signal, so that
822 can be used as a wrapper process transparent to the invoking parent process.
823 Note that parent-child relationship (signal stop notifications,
824 getppid() value, etc) between traced process and its parent are not preserved
835 is zero unless no processes has been attached or there was an unexpected error
836 in doing the tracing.
837 .SH "SETUID INSTALLATION"
840 is installed setuid to root then the invoking user will be able to
841 attach to and trace processes owned by any user.
842 In addition setuid and setgid programs will be executed and traced
843 with the correct effective privileges.
844 Since only users trusted with full root privileges should be allowed
846 it only makes sense to install
848 as setuid to root when the users who can execute it are restricted
849 to those users who have this trust.
850 For example, it makes sense to install a special version of
852 with mode 'rwsr-xr--', user
858 group are trusted users.
859 If you do use this feature, please remember to install
860 a non-setuid version of
862 for ordinary lusers to use.
864 It is a pity that so much tracing clutter is produced by systems
865 employing shared libraries.
867 It is instructive to think about system call inputs and outputs
868 as data-flow across the user/kernel boundary. Because user-space
869 and kernel-space are separate and address-protected, it is
870 sometimes possible to make deductive inferences about process
871 behavior using inputs and outputs as propositions.
873 In some cases, a system call will differ from the documented behavior
874 or have a different name. For example, the
876 system call does not have
880 library function uses
882 system call on modern (2.6.38+) kernels. These
883 discrepancies are normal but idiosyncratic characteristics of the
884 system call interface and are accounted for by C library wrapper
887 Some system calls have different names in different architectures and
888 personalities. In these cases, system call filtering and printing
889 uses the names that match corresponding
891 kernel macros of the tracee's architecture and personality.
892 There are two exceptions from this general rule:
893 .BR arm_fadvise64_64 (2)
895 .BR xtensa_fadvise64_64 (2)
896 Xtensa syscall are filtered and printed as
897 .BR fadvise64_64 (2).
899 On some platforms a process that is attached to with the
901 option may observe a spurious EINTR return from the current
902 system call that is not restartable. (Ideally, all system calls
903 should be restarted on strace attach, making the attach invisible
904 to the traced process, but a few system calls aren't.
905 Arguably, every instance of such behavior is a kernel bug.)
906 This may have an unpredictable effect on the process
907 if the process takes no action to restart the system call.
909 Programs that use the
914 privileges while being traced.
916 A traced process runs slowly.
918 Traced processes which are descended from
920 may be left running after an interrupt signal (\c
925 was written by Paul Kranenburg
926 for SunOS and was inspired by its trace utility.
929 was ported to Linux and enhanced
930 by Branko Lankester, who also wrote the Linux kernel support.
931 Even though Paul released
934 Branko's work was based on Paul's
936 1.5 release from 1991.
937 In 1993, Rick Sladkey merged
939 2.5 for SunOS and the second release of
941 for Linux, added many of the features of
943 from SVR4, and produced an
945 that worked on both platforms. In 1994 Rick ported
947 to SVR4 and Solaris and wrote the
948 automatic configuration support. In 1995 he ported
951 and tired of writing about himself in the third person.
955 should be reported to the
957 mailing list at <strace\-devel@lists.sourceforge.net>.
959 .BR strace-log-merge (1),