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 .\" Like .OP, but with ellipsis at the end in order to signify that option
39 .\" can be provided multiple times. Based on .OP definition in groff's
43 . RI "[\fB\\$1\fP" "\ \\$2" "]...\&"
45 . RB "[" "\\$1" "]...\&"
50 . RI "\fB\\$1\fP" "\ \\$2"
54 .TH STRACE 1 "@MANPAGE_DATE@" "strace @VERSION@"
56 strace \- trace system calls and signals
59 .OP \-CdffhikqrtttTvVxxy
72 .OM \-E var\fR[=\fIval\fR]
74 .IR command " [" args ]
91 .OM \-E var\fR[=\fIval\fR]
93 .IR command " [" args ]
98 .IX "strace command" "" "\fLstrace\fR command"
105 It intercepts and records the system calls which are called
106 by a process and the signals which are received by a process.
107 The name of each system call, its arguments and its return value
108 are printed on standard error or to the file specified with the
113 is a useful diagnostic, instructional, and debugging tool.
114 System administrators, diagnosticians and trouble-shooters will find
115 it invaluable for solving problems with
116 programs for which the source is not readily available since
117 they do not need to be recompiled in order to trace them.
118 Students, hackers and the overly-curious will find that
119 a great deal can be learned about a system and its system calls by
120 tracing even ordinary programs. And programmers will find that
121 since system calls and signals are events that happen at the user/kernel
122 interface, a close examination of this boundary is very
123 useful for bug isolation, sanity checking and
124 attempting to capture race conditions.
126 Each line in the trace contains the system call name, followed
127 by its arguments in parentheses and its return value.
128 An example from stracing the command "cat /dev/null" is:
130 open("/dev/null", O_RDONLY) = 3
132 Errors (typically a return value of \-1) have the errno symbol
133 and error string appended.
135 open("/foo/bar", O_RDONLY) = \-1 ENOENT (No such file or directory)
137 Signals are printed as signal symbol and decoded siginfo structure.
138 An excerpt from stracing and interrupting the command "sleep 666" is:
140 sigsuspend([] <unfinished ...>
141 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
142 +++ killed by SIGINT +++
144 If a system call is being executed and meanwhile another one is being called
145 from a different thread/process then
147 will try to preserve the order of those events and mark the ongoing call as
150 When the call returns it will be marked as
153 [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
154 [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
155 [pid 28772] <... select resumed> ) = 1 (in [3])
157 Interruption of a (restartable) system call by a signal delivery is processed
158 differently as kernel terminates the system call and also arranges its
159 immediate reexecution after the signal handler completes.
161 read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted)
163 rt_sigreturn(0xe) = 0
166 Arguments are printed in symbolic form with a passion.
167 This example shows the shell performing ">>xyzzy" output redirection:
169 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
171 Here the third argument of open is decoded by breaking down the
172 flag argument into its three bitwise-OR constituents and printing the
173 mode value in octal by tradition. Where traditional or native
174 usage differs from ANSI or POSIX, the latter forms are preferred.
177 output has proven to be more readable than the source.
179 Structure pointers are dereferenced and the members are displayed
180 as appropriate. In all cases arguments are formatted in the most C-like
182 For example, the essence of the command "ls \-l /dev/null" is captured as:
184 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
186 Notice how the 'struct stat' argument is dereferenced and how each member is
187 displayed symbolically. In particular, observe how the st_mode member
188 is carefully decoded into a bitwise-OR of symbolic and numeric values.
189 Also notice in this example that the first argument to lstat is an input
190 to the system call and the second argument is an output. Since output
191 arguments are not modified if the system call fails, arguments may not
192 always be dereferenced. For example, retrying the "ls \-l" example
193 with a non-existent file produces the following line:
195 lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
197 In this case the porch light is on but nobody is home.
199 Character pointers are dereferenced and printed as C strings.
200 Non-printing characters in strings are normally represented by
201 ordinary C escape codes.
204 (32 by default) bytes of strings are printed;
205 longer strings have an ellipsis appended following the closing quote.
206 Here is a line from "ls \-l" where the
208 library routine is reading the password file:
210 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
212 While structures are annotated using curly braces, simple pointers
213 and arrays are printed using square brackets with commas separating
214 elements. Here is an example from the command "id" on a system with
215 supplementary group ids:
217 getgroups(32, [100, 0]) = 2
219 On the other hand, bit-sets are also shown using square brackets
220 but set elements are separated only by a space. Here is the shell
221 preparing to execute an external command:
223 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
225 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
226 In some cases the bit-set is so full that printing out the unset
227 elements is more valuable. In that case, the bit-set is prefixed by
230 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
232 Here the second argument represents the full set of all signals.
237 Align return values in a specific column (default column 40).
240 Print the instruction pointer at the time of the system call.
243 Print the execution stack trace of the traced processes after each system call (experimental).
244 This option is available only if
246 is built with libunwind.
249 Write the trace output to the file
251 rather than to stderr.
257 If the argument begins with '|' or with '!' then the rest of the
258 argument is treated as a command and all output is piped to it.
259 This is convenient for piping the debugging output to a program
260 without affecting the redirections of executed programs.
263 Suppress messages about attaching, detaching etc. This happens
264 automatically when output is redirected to a file and the command
265 is run directly instead of attaching.
268 If given twice, suppress messages about process exit status.
271 Print a relative timestamp upon entry to each system call. This
272 records the time difference between the beginning of successive
276 Specify the maximum string size to print (the default is 32). Note
277 that filenames are not considered strings and are always printed in
281 Prefix each line of the trace with the time of day.
284 If given twice, the time printed will include the microseconds.
287 If given thrice, the time printed will include the microseconds
288 and the leading portion will be printed as the number
289 of seconds since the epoch.
292 Show the time spent in system calls. This records the time
293 difference between the beginning and the end of each system call.
296 Print all non-ASCII strings in hexadecimal string format.
299 Print all strings in hexadecimal string format.
302 Print paths associated with file descriptor arguments.
305 Print protocol specific information associated with socket file descriptors.
309 Count time, calls, and errors for each system call and report a summary on
310 program exit. On Linux, this attempts to show system time (CPU time spent
311 running in the kernel) independent of wall clock time. If
317 , only aggregate totals for all traced processes are kept.
322 but also print regular output while processes are running.
325 Set the overhead for tracing system calls to
328 This is useful for overriding the default heuristic for guessing
329 how much time is spent in mere measuring when timing system calls using
332 option. The accuracy of the heuristic can be gauged by timing a given
333 program run without tracing (using
335 and comparing the accumulated
336 system call time to the total produced using
340 Sort the output of the histogram printed by the
342 option by the specified criterion. Legal values are
352 Summarise the time difference between the beginning and end of
353 each system call. The default is to summarise the system time.
357 A qualifying expression which modifies which events to trace
358 or how to trace them. The format of the expression is:
361 [\,\fIqualifier\/\fB=\fR][\fB!\fR][\fB?\fR]\,\fIvalue1\/\fR[\fB,\fR[\fB?\fR]\,\fIvalue2\/\fR]...
379 is a qualifier-dependent symbol or number. The default
382 Using an exclamation mark negates the set of values. For example,
385 .BR \-e "\ " trace = open
386 which in turn means trace only the
388 system call. By contrast,
389 .BR \-e "\ " trace "=!" open
390 means to trace every system call except
392 Question mark before the syscall qualification allows suppression of error
393 in case no syscalls matched the qualification provided.
394 In addition, the special values
398 have the obvious meanings.
400 Note that some shells use the exclamation point for history
401 expansion even inside quoted arguments. If so, you must escape
402 the exclamation point with a backslash.
404 \fB\-e\ trace\fR=\,\fIset\fR
405 Trace only the specified set of system calls. The
407 option is useful for determining which system calls might be useful
408 to trace. For example,
409 .BR trace = open,close,read,write
411 trace those four system calls. Be careful when making inferences
412 about the user/kernel boundary if only a subset of system calls
413 are being monitored. The default is
416 \fB\-e\ trace\fR=/\,\fIregex\fR
417 Trace only those system calls that match the
421 Extended Regular Expression syntax (see
424 .BR "\-e\ trace" = %file
426 .BR "\-e\ trace" = file " (deprecated)"
427 Trace all system calls which take a file name as an argument. You
428 can think of this as an abbreviation for
429 .BR "\-e\ trace" = open , stat , chmod , unlink ,...
430 which is useful to seeing what files the process is referencing.
431 Furthermore, using the abbreviation will ensure that you don't
432 accidentally forget to include a call like
434 in the list. Betchya woulda forgot that one.
436 .BR "\-e\ trace" = %process
438 .BR "\-e\ trace" = process " (deprecated)"
439 Trace all system calls which involve process management. This
440 is useful for watching the fork, wait, and exec steps of a process.
442 .BR "\-e\ trace" = %network
444 .BR "\-e\ trace" = network " (deprecated)"
445 Trace all the network related system calls.
447 .BR "\-e\ trace" = %signal
449 .BR "\-e\ trace" = signal " (deprecated)"
450 Trace all signal related system calls.
452 .BR "\-e\ trace" = %ipc
454 .BR "\-e\ trace" = ipc " (deprecated)"
455 Trace all IPC related system calls.
457 .BR "\-e\ trace" = %desc
459 .BR "\-e\ trace" = desc " (deprecated)"
460 Trace all file descriptor related system calls.
462 .BR "\-e\ trace" = %memory
464 .BR "\-e\ trace" = memory " (deprecated)"
465 Trace all memory mapping related system calls.
467 .BR "\-e\ trace" = %stat
468 Trace stat syscall variants.
470 .BR "\-e\ trace" = %lstat
471 Trace lstat syscall variants.
473 .BR "\-e\ trace" = %fstat
474 Trace fstat and fstatat syscall variants.
476 .BR "\-e\ trace" = %%stat
477 Trace syscalls used for requesting file status (stat, lstat, fstat, fstatat,
478 statx, and their variants).
480 .BR "\-e\ trace" = %statfs
481 Trace statfs, statfs64, statvfs, osf_statfs, and osf_statfs64 system calls.
482 The same effect can be achieved with
483 .BR "\-e\ trace" = /^(.*_)?statv?fs
486 .BR "\-e\ trace" = %fstatfs
487 Trace fstatfs, fstatfs64, fstatvfs, osf_fstatfs, and osf_fstatfs64 system calls.
488 The same effect can be achieved with
489 .BR "\-e\ trace" = /fstatv?fs
492 .BR "\-e\ trace" = %%statfs
493 Trace syscalls related to file system statistics (statfs-like, fstatfs-like,
494 and ustat). The same effect can be achieved with
495 .BR "\-e\ trace" = /statv?fs|fsstat|ustat
498 \fB\-e\ abbrev\fR=\,\fIset\fR
499 Abbreviate the output from printing each member of large structures.
504 option has the effect of
507 \fB\-e\ verbose\fR=\,\fIset\fR
508 Dereference structures for the specified set of system calls. The
512 \fB\-e\ raw\fR=\,\fIset\fR
513 Print raw, undecoded arguments for the specified set of system calls.
514 This option has the effect of causing all arguments to be printed
515 in hexadecimal. This is mostly useful if you don't trust the
516 decoding or you need to know the actual numeric value of an
519 \fB\-e\ signal\fR=\,\fIset\fR
520 Trace only the specified subset of signals. The default is
526 causes SIGIO signals not to be traced.
528 \fB\-e\ read\fR=\,\fIset\fR
529 Perform a full hexadecimal and ASCII dump of all the data read from
530 file descriptors listed in the specified set. For example, to see
531 all input activity on file descriptors
536 \fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
537 Note that this is independent from the normal tracing of the
539 system call which is controlled by the option
540 .BR -e "\ " trace = read .
542 \fB\-e\ write\fR=\,\fIset\fR
543 Perform a full hexadecimal and ASCII dump of all the data written to
544 file descriptors listed in the specified set. For example, to see
545 all output activity on file descriptors
550 \fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
551 Note that this is independent from the normal tracing of the
553 system call which is controlled by the option
554 .BR -e "\ " trace = write .
556 \fB\-e\ inject\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR|:\fBretval\fR=\,\fIvalue\/\fR][:\fBsignal\fR=\,\fIsig\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
557 Perform syscall tampering for the specified set of syscalls.
564 options has to be specified.
568 are mutually exclusive.
570 If :\fBerror\fR=\,\fIerrno\/\fR option is specified,
571 a fault is injected into a syscall invocation:
572 the syscall number is replaced by -1 which corresponds to an invalid syscall,
573 and the error code is specified using a symbolic
577 or a numeric value within 1..4095 range.
579 If :\fBretval\fR=\,\fIvalue\/\fR option is specified,
580 success injection is performed: the syscall number is replaced by -1,
581 but a bogus success value is returned to the callee.
583 If :\fBsignal\fR=\,\fIsig\/\fR option is specified with either a symbolic value
586 or a numeric value within 1..\fBSIGRTMAX\fR range,
587 that signal is delivered on entering every syscall specified by the
590 If :\fBsignal\fR=\,\fIsig\/\fR option is specified without
591 :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR options,
594 is delivered without a syscall fault injection.
595 Conversely, :\fBerror\fR=\,\fIerrno\/\fR or
596 :\fBretval\fR=\,\fIvalue\/\fR option without
597 :\fBsignal\fR=\,\fIsig\/\fR option injects a fault without delivering a signal.
599 If both :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR
600 and :\fBsignal\fR=\,\fIsig\/\fR options are specified, then both
601 a fault or success is injected and a signal is delivered.
603 Unless a :\fBwhen\fR=\,\fIexpr\fR subexpression is specified,
604 an injection is being made into every invocation of each syscall from the
607 The format of the subexpression is one of the following:
612 For every syscall from the
614 perform an injection for the syscall invocation number
621 For every syscall from the
623 perform injections for the syscall invocation number
625 and all subsequent invocations.
628 \fIfirst\/\fB+\fIstep\fR
630 For every syscall from the
632 perform injections for syscall invocations number
635 .IR first + step + step ,
640 For example, to fail each third and subsequent chdir syscalls with
643 \fB\-e\ inject\fR=\,\fIchdir\/\fR:\fBerror\fR=\,\fIENOENT\/\fR:\fBwhen\fR=\,\fI3\/\fB+\fR.
645 The valid range for numbers
651 An injection expression can contain only one
656 If an injection expression contains multiple
658 specifications, the last one takes precedence.
660 Accounting of syscalls that are subject to injection
661 is done per syscall and per tracee.
663 Specification of syscall injection can be combined
664 with other syscall filtering options, for example,
665 \fB\-P \fI/dev/urandom \fB\-e inject\fR=\,\fIfile\/\fR:\fBerror\fR=\,\fIENOENT\fR.
668 \fB\-e\ fault\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
669 Perform syscall fault injection for the specified set of syscalls.
671 This is equivalent to more generic
672 \fB\-e\ inject\fR= expression with default value of
679 Trace only system calls accessing
683 options can be used to specify several paths.
686 Print unabbreviated versions of environment, stat, termios, etc.
687 calls. These structures are very common in calls and so the default
688 behavior displays a reasonable subset of structure members. Use
689 this option to get all of the gory details.
693 If specified syscall is reached, detach from traced process.
696 syscall is supported. This option is useful if you want to trace
697 multi-threaded process and therefore require -f, but don't want
698 to trace its (potentially very complex) children.
701 Run tracer process as a detached grandchild, not as parent of the
702 tracee. This reduces the visible effect of
704 by keeping the tracee a direct child of the calling process.
707 Trace child processes as they are created by currently traced
708 processes as a result of the
713 system calls. Note that
717 will attach all threads of process PID if it is multi-threaded,
718 not only thread with thread_id = PID.
724 option is in effect, each processes trace is written to
726 where pid is the numeric process id of each process.
727 This is incompatible with
729 since no per-process counts are kept.
731 .BI "\-I " interruptible
732 When strace can be interrupted by signals (such as pressing ^C).
733 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
734 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
735 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
736 strace -o FILE PROG not stop on ^Z).
739 \fB\-E\ \fIvar\fR=\,\fIval\fR
742 in its list of environment variables.
747 from the inherited list of environment variables before passing it on to
751 Attach to the process with the process
755 The trace may be terminated
756 at any time by a keyboard interrupt signal (\c
759 will respond by detaching itself from the traced process(es)
760 leaving it (them) to continue running.
763 options can be used to attach to many processes in addition to
765 (which is optional if at least one
769 "`pidof PROG`" syntax is supported.
772 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
773 supplementary groups of
775 This option is only useful when running as root and enables the
776 correct execution of setuid and/or setgid binaries.
777 Unless this option is used setuid and setgid programs are executed
778 without effective privileges.
782 Show some debugging output of
784 itself on the standard error.
787 This option is now obsolete and it has the same functionality as
791 Print the help summary.
794 Print the version number of
801 exits with the same exit status.
804 is terminated by a signal,
806 terminates itself with the same signal, so that
808 can be used as a wrapper process transparent to the invoking parent process.
809 Note that parent-child relationship (signal stop notifications,
810 getppid() value, etc) between traced process and its parent are not preserved
821 is zero unless no processes has been attached or there was an unexpected error
822 in doing the tracing.
823 .SH "SETUID INSTALLATION"
826 is installed setuid to root then the invoking user will be able to
827 attach to and trace processes owned by any user.
828 In addition setuid and setgid programs will be executed and traced
829 with the correct effective privileges.
830 Since only users trusted with full root privileges should be allowed
832 it only makes sense to install
834 as setuid to root when the users who can execute it are restricted
835 to those users who have this trust.
836 For example, it makes sense to install a special version of
838 with mode 'rwsr-xr--', user
844 group are trusted users.
845 If you do use this feature, please remember to install
846 a non-setuid version of
848 for ordinary lusers to use.
850 It is a pity that so much tracing clutter is produced by systems
851 employing shared libraries.
853 It is instructive to think about system call inputs and outputs
854 as data-flow across the user/kernel boundary. Because user-space
855 and kernel-space are separate and address-protected, it is
856 sometimes possible to make deductive inferences about process
857 behavior using inputs and outputs as propositions.
859 In some cases, a system call will differ from the documented behavior
860 or have a different name. For example, on System V-derived systems
863 system call does not take an argument and the
867 and takes an extra leading argument. These
868 discrepancies are normal but idiosyncratic characteristics of the
869 system call interface and are accounted for by C library wrapper
872 Some system calls have different names in different architectures and
873 personalities. In these cases, system call filtering and printing
874 uses the names that match corresponding
876 kernel macros of the tracee's architecture and personality.
877 There are two exceptions from this general rule:
878 .BR arm_fadvise64_64 (2)
880 .BR xtensa_fadvise64_64 (2)
881 Xtensa syscall are filtered and printed as
882 .BR fadvise64_64 (2).
884 On some platforms a process that is attached to with the
886 option may observe a spurious EINTR return from the current
887 system call that is not restartable. (Ideally, all system calls
888 should be restarted on strace attach, making the attach invisible
889 to the traced process, but a few system calls aren't.
890 Arguably, every instance of such behavior is a kernel bug.)
891 This may have an unpredictable effect on the process
892 if the process takes no action to restart the system call.
894 Programs that use the
899 privileges while being traced.
901 A traced process runs slowly.
903 Traced processes which are descended from
905 may be left running after an interrupt signal (\c
910 was written by Paul Kranenburg
911 for SunOS and was inspired by its trace utility.
914 was ported to Linux and enhanced
915 by Branko Lankester, who also wrote the Linux kernel support.
916 Even though Paul released
919 Branko's work was based on Paul's
921 1.5 release from 1991.
922 In 1993, Rick Sladkey merged
924 2.5 for SunOS and the second release of
926 for Linux, added many of the features of
928 from SVR4, and produced an
930 that worked on both platforms. In 1994 Rick ported
932 to SVR4 and Solaris and wrote the
933 automatic configuration support. In 1995 he ported
936 and tired of writing about himself in the third person.
940 should be reported to the
942 mailing list at <strace\-devel@lists.sourceforge.net>.