]> granicus.if.org Git - strace/blob - strace.1
bpf: update BPF_PROG_ATTACH decoding
[strace] / strace.1
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.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
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.
16 .\"
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.
27 .de CW
28 .sp
29 .nf
30 .ft CW
31 ..
32 .de CE
33 .ft R
34 .fi
35 .sp
36 ..
37 .\" Macro IX is not defined in the groff macros
38 .if \n(.g \{\
39 .  de IX
40 ..
41 .\}
42 .TH STRACE 1 "2010-03-30"
43 .SH NAME
44 strace \- trace system calls and signals
45 .SH SYNOPSIS
46 .B strace
47 [\fB-CdffhikqrtttTvVxxy\fR]
48 [\fB-I\fIn\fR]
49 [\fB-b\fIexecve\fR]
50 [\fB-e\fIexpr\fR]...
51 [\fB-a\fIcolumn\fR]
52 [\fB-o\fIfile\fR]
53 [\fB-s\fIstrsize\fR]
54 [\fB-P\fIpath\fR]... \fB-p\fIpid\fR... /
55 [\fB-D\fR]
56 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
57 \fIcommand\fR [\fIargs\fR]
58 .sp
59 .B strace
60 \fB-c\fR[\fBdf\fR]
61 [\fB-I\fIn\fR]
62 [\fB-b\fIexecve\fR]
63 [\fB-e\fIexpr\fR]...
64 [\fB-O\fIoverhead\fR]
65 [\fB-S\fIsortby\fR] \fB-p\fIpid\fR... /
66 [\fB-D\fR]
67 [\fB-E\fIvar\fR[=\fIval\fR]]... [\fB-u\fIusername\fR]
68 \fIcommand\fR [\fIargs\fR]
69 .SH DESCRIPTION
70 .IX "strace command" "" "\fLstrace\fR command"
71 .LP
72 In the simplest case
73 .B strace
74 runs the specified
75 .I command
76 until it exits.
77 It intercepts and records the system calls which are called
78 by a process and the signals which are received by a process.
79 The name of each system call, its arguments and its return value
80 are printed on standard error or to the file specified with the
81 .B \-o
82 option.
83 .LP
84 .B strace
85 is a useful diagnostic, instructional, and debugging tool.
86 System administrators, diagnosticians and trouble-shooters will find
87 it invaluable for solving problems with
88 programs for which the source is not readily available since
89 they do not need to be recompiled in order to trace them.
90 Students, hackers and the overly-curious will find that
91 a great deal can be learned about a system and its system calls by
92 tracing even ordinary programs.  And programmers will find that
93 since system calls and signals are events that happen at the user/kernel
94 interface, a close examination of this boundary is very
95 useful for bug isolation, sanity checking and
96 attempting to capture race conditions.
97 .LP
98 Each line in the trace contains the system call name, followed
99 by its arguments in parentheses and its return value.
100 An example from stracing the command "cat /dev/null" is:
101 .CW
102 open("/dev/null", O_RDONLY) = 3
103 .CE
104 Errors (typically a return value of \-1) have the errno symbol
105 and error string appended.
106 .CW
107 open("/foo/bar", O_RDONLY) = \-1 ENOENT (No such file or directory)
108 .CE
109 Signals are printed as signal symbol and decoded siginfo structure.
110 An excerpt from stracing and interrupting the command "sleep 666" is:
111 .CW
112 sigsuspend([] <unfinished ...>
113 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} ---
114 +++ killed by SIGINT +++
115 .CE
116 If a system call is being executed and meanwhile another one is being called
117 from a different thread/process then
118 .B strace
119 will try to preserve the order of those events and mark the ongoing call as
120 being
121 .IR unfinished .
122 When the call returns it will be marked as
123 .IR resumed .
124 .CW
125 [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
126 [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
127 [pid 28772] <... select resumed> )      = 1 (in [3])
128 .CE
129 Interruption of a (restartable) system call by a signal delivery is processed
130 differently as kernel terminates the system call and also arranges its
131 immediate reexecution after the signal handler completes.
132 .CW
133 read(0, 0x7ffff72cf5cf, 1)              = ? ERESTARTSYS (To be restarted)
134 --- SIGALRM ... ---
135 rt_sigreturn(0xe)                       = 0
136 read(0, "", 1)                          = 0
137 .CE
138 Arguments are printed in symbolic form with a passion.
139 This example shows the shell performing ">>xyzzy" output redirection:
140 .CW
141 open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
142 .CE
143 Here the third argument of open is decoded by breaking down the
144 flag argument into its three bitwise-OR constituents and printing the
145 mode value in octal by tradition.  Where traditional or native
146 usage differs from ANSI or POSIX, the latter forms are preferred.
147 In some cases,
148 .B strace
149 output has proven to be more readable than the source.
150 .LP
151 Structure pointers are dereferenced and the members are displayed
152 as appropriate.  In all cases arguments are formatted in the most C-like
153 fashion possible.
154 For example, the essence of the command "ls \-l /dev/null" is captured as:
155 .CW
156 lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
157 .CE
158 Notice how the 'struct stat' argument is dereferenced and how each member is
159 displayed symbolically.  In particular, observe how the st_mode member
160 is carefully decoded into a bitwise-OR of symbolic and numeric values.
161 Also notice in this example that the first argument to lstat is an input
162 to the system call and the second argument is an output.  Since output
163 arguments are not modified if the system call fails, arguments may not
164 always be dereferenced.  For example, retrying the "ls \-l" example
165 with a non-existent file produces the following line:
166 .CW
167 lstat("/foo/bar", 0xb004) = \-1 ENOENT (No such file or directory)
168 .CE
169 In this case the porch light is on but nobody is home.
170 .LP
171 Character pointers are dereferenced and printed as C strings.
172 Non-printing characters in strings are normally represented by
173 ordinary C escape codes.
174 Only the first
175 .I strsize
176 (32 by default) bytes of strings are printed;
177 longer strings have an ellipsis appended following the closing quote.
178 Here is a line from "ls \-l" where the
179 .B getpwuid
180 library routine is reading the password file:
181 .CW
182 read(3, "root::0:0:System Administrator:/"..., 1024) = 422
183 .CE
184 While structures are annotated using curly braces, simple pointers
185 and arrays are printed using square brackets with commas separating
186 elements.  Here is an example from the command "id" on a system with
187 supplementary group ids:
188 .CW
189 getgroups(32, [100, 0]) = 2
190 .CE
191 On the other hand, bit-sets are also shown using square brackets
192 but set elements are separated only by a space.  Here is the shell
193 preparing to execute an external command:
194 .CW
195 sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
196 .CE
197 Here the second argument is a bit-set of two signals, SIGCHLD and SIGTTOU.
198 In some cases the bit-set is so full that printing out the unset
199 elements is more valuable.  In that case, the bit-set is prefixed by
200 a tilde like this:
201 .CW
202 sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
203 .CE
204 Here the second argument represents the full set of all signals.
205 .SH OPTIONS
206 .SS Output format
207 .TP 12
208 .BI "\-a " column
209 Align return values in a specific column (default column 40).
210 .TP
211 .B \-i
212 Print the instruction pointer at the time of the system call.
213 .TP
214 .B \-k
215 Print the execution stack trace of the traced processes after each system call (experimental).
216 This option is available only if
217 .B strace
218 is built with libunwind.
219 .TP
220 .BI "\-o " filename
221 Write the trace output to the file
222 .I filename
223 rather than to stderr.
224 Use
225 .I filename.pid
226 if
227 .B \-ff
228 is used.
229 If the argument begins with '|' or with '!' then the rest of the
230 argument is treated as a command and all output is piped to it.
231 This is convenient for piping the debugging output to a program
232 without affecting the redirections of executed programs.
233 .TP
234 .B \-q
235 Suppress messages about attaching, detaching etc.  This happens
236 automatically when output is redirected to a file and the command
237 is run directly instead of attaching.
238 .TP
239 .B \-qq
240 If given twice, suppress messages about process exit status.
241 .TP
242 .B \-r
243 Print a relative timestamp upon entry to each system call.  This
244 records the time difference between the beginning of successive
245 system calls.
246 .TP
247 .BI "\-s " strsize
248 Specify the maximum string size to print (the default is 32).  Note
249 that filenames are not considered strings and are always printed in
250 full.
251 .TP
252 .B \-t
253 Prefix each line of the trace with the time of day.
254 .TP
255 .B \-tt
256 If given twice, the time printed will include the microseconds.
257 .TP
258 .B \-ttt
259 If given thrice, the time printed will include the microseconds
260 and the leading portion will be printed as the number
261 of seconds since the epoch.
262 .TP
263 .B \-T
264 Show the time spent in system calls.  This records the time
265 difference between the beginning and the end of each system call.
266 .TP
267 .B \-x
268 Print all non-ASCII strings in hexadecimal string format.
269 .TP
270 .B \-xx
271 Print all strings in hexadecimal string format.
272 .TP
273 .B \-y
274 Print paths associated with file descriptor arguments.
275 .TP
276 .B \-yy
277 Print protocol specific information associated with socket file descriptors.
278 .SS Statistics
279 .TP 12
280 .B \-c
281 Count time, calls, and errors for each system call and report a summary on
282 program exit.  On Linux, this attempts to show system time (CPU time spent
283 running in the kernel) independent of wall clock time.  If
284 .B \-c
285 is used with
286 .B \-f
287 or
288 .B \-F
289 , only aggregate totals for all traced processes are kept.
290 .TP
291 .B \-C
292 Like
293 .B \-c
294 but also print regular output while processes are running.
295 .TP
296 .BI "\-O " overhead
297 Set the overhead for tracing system calls to
298 .I overhead
299 microseconds.
300 This is useful for overriding the default heuristic for guessing
301 how much time is spent in mere measuring when timing system calls using
302 the
303 .B \-c
304 option.  The accuracy of the heuristic can be gauged by timing a given
305 program run without tracing (using
306 .BR time (1))
307 and comparing the accumulated
308 system call time to the total produced using
309 .BR \-c .
310 .TP
311 .BI "\-S " sortby
312 Sort the output of the histogram printed by the
313 .B \-c
314 option by the specified criterion.  Legal values are
315 .BR time ,
316 .BR calls ,
317 .BR name ,
318 and
319 .B nothing
320 (default is
321 .BR time ).
322 .TP
323 .B \-w
324 Summarise the time difference between the beginning and end of
325 each system call.  The default is to summarise the system time.
326 .SS Filtering
327 .TP 12
328 .BI "\-e " expr
329 A qualifying expression which modifies which events to trace
330 or how to trace them.  The format of the expression is:
331 .RS 15
332 .IP
333 [\,\fIqualifier\/\fB=\fR][\fB!\fR]\,\fIvalue1\/\fR[\fB,\,\fIvalue2\/\fR]...
334 .RE
335 .IP
336 where
337 .I qualifier
338 is one of
339 .BR trace ,
340 .BR abbrev ,
341 .BR verbose ,
342 .BR raw ,
343 .BR signal ,
344 .BR read ,
345 .BR write ,
346 .BR fault ,
347 or
348 .B inject
349 and
350 .I value
351 is a qualifier-dependent symbol or number.  The default
352 qualifier is
353 .BR trace .
354 Using an exclamation mark negates the set of values.  For example,
355 .BR \-e "\ " open
356 means literally
357 .BR \-e "\ " trace = open
358 which in turn means trace only the
359 .B open
360 system call.  By contrast,
361 .BR \-e "\ " trace "=!" open
362 means to trace every system call except
363 .BR open .
364 In addition, the special values
365 .B all
366 and
367 .B none
368 have the obvious meanings.
369 .IP
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.
373 .TP
374 \fB\-e\ trace\fR=\,\fIset\fR
375 Trace only the specified set of system calls.  The
376 .B \-c
377 option is useful for determining which system calls might be useful
378 to trace.  For example,
379 .BR trace = open,close,read,write
380 means to only
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
384 .BR trace = all .
385 .TP
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
393 .B lstat
394 in the list.  Betchya woulda forgot that one.
395 .TP
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.
399 .TP
400 .BR "\-e\ trace" = network
401 Trace all the network related system calls.
402 .TP
403 .BR "\-e\ trace" = signal
404 Trace all signal related system calls.
405 .TP
406 .BR "\-e\ trace" = ipc
407 Trace all IPC related system calls.
408 .TP
409 .BR "\-e\ trace" = desc
410 Trace all file descriptor related system calls.
411 .TP
412 .BR "\-e\ trace" = memory
413 Trace all memory mapping related system calls.
414 .TP
415 \fB\-e\ abbrev\fR=\,\fIset\fR
416 Abbreviate the output from printing each member of large structures.
417 The default is
418 .BR abbrev = all .
419 The
420 .B \-v
421 option has the effect of
422 .BR abbrev = none .
423 .TP
424 \fB\-e\ verbose\fR=\,\fIset\fR
425 Dereference structures for the specified set of system calls.  The
426 default is
427 .BR verbose = all .
428 .TP
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
434 argument.
435 .TP
436 \fB\-e\ signal\fR=\,\fIset\fR
437 Trace only the specified subset of signals.  The default is
438 .BR signal = all .
439 For example,
440 .B signal "=!" SIGIO
441 (or
442 .BR signal "=!" io )
443 causes SIGIO signals not to be traced.
444 .TP
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
449 .I 3
450 and
451 .I 5
452 use
453 \fB\-e\ read\fR=\,\fI3\fR,\fI5\fR.
454 Note that this is independent from the normal tracing of the
455 .BR read (2)
456 system call which is controlled by the option
457 .BR -e "\ " trace = read .
458 .TP
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
463 .I 3
464 and
465 .I 5
466 use
467 \fB\-e\ write\fR=\,\fI3\fR,\,\fI5\fR.
468 Note that this is independent from the normal tracing of the
469 .BR write (2)
470 system call which is controlled by the option
471 .BR -e "\ " trace = write .
472 .TP
473 \fB\-e\ inject\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR|:\fBretval\fR=\,\fIvalue\/\fR][:\fBsignal\fR=\,\fIsig\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
474 Perform syscall tampering for the specified set of syscalls.
475
476 At least one of
477 .BR error ,
478 .BR retval ,
479 or
480 .B signal
481 options has to be specified.
482 .B error
483 and
484 .B retval
485 are mutually exclusive.
486
487 If :\fBerror\fR=\,\fIerrno\/\fR option is specified,
488 a fault is injected into a syscall invocation:
489 the syscall number is replaced by -1 which corresponds to an invalid syscall,
490 and the error code is specified using a symbolic
491 .I errno
492 value like
493 .B ENOSYS
494 or a numeric value within 1..4095 range.
495
496 If :\fBretval\fR=\,\fIvalue\/\fR option is specified,
497 success injection is performed: the syscall number is replaced by -1,
498 but a bogus success value is returned to the callee.
499
500 If :\fBsignal\fR=\,\fIsig\/\fR option is specified with either a symbolic value
501 like
502 .B SIGSEGV
503 or a numeric value within 1..\fBSIGRTMAX\fR range,
504 that signal is delivered on entering every syscall specified by the
505 .IR set .
506
507 If :\fBsignal\fR=\,\fIsig\/\fR option is specified without
508 :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR options,
509 then only a signal
510 .I sig
511 is delivered without a syscall fault injection.
512 Conversely, :\fBerror\fR=\,\fIerrno\/\fR or
513 :\fBretval\fR=\,\fIvalue\/\fR option without
514 :\fBsignal\fR=\,\fIsig\/\fR option injects a fault without delivering a signal.
515
516 If both :\fBerror\fR=\,\fIerrno\/\fR or :\fBretval\fR=\,\fIvalue\/\fR
517 and :\fBsignal\fR=\,\fIsig\/\fR options are specified, then both
518 a fault or success is injected and a signal is delivered.
519
520 Unless a :\fBwhen\fR=\,\fIexpr\fR subexpression is specified,
521 an injection is being made into every invocation of each syscall from the
522 .IR set .
523
524 The format of the subexpression is one of the following:
525 .RS
526 .IP "" 2
527 .I first
528 .RS 4
529 For every syscall from the
530 .IR set ,
531 perform an injection for the syscall invocation number
532 .I first
533 only.
534 .RE
535 .IP "" 2
536 \fIfirst\/\fB+\fR
537 .RS 4
538 For every syscall from the
539 .IR set ,
540 perform injections for the syscall invocation number
541 .I first
542 and all subsequent invocations.
543 .RE
544 .IP "" 2
545 \fIfirst\/\fB+\fIstep\fR
546 .RS 4
547 For every syscall from the
548 .IR set ,
549 perform injections for syscall invocations number
550 .IR first ,
551 .IR first + step ,
552 .IR first + step + step ,
553 and so on.
554 .RE
555 .RE
556 .IP
557 For example, to fail each third and subsequent chdir syscalls with
558 .BR ENOENT ,
559 use
560 \fB\-e\ inject\fR=\,\fIchdir\/\fR:\fBerror\fR=\,\fIENOENT\/\fR:\fBwhen\fR=\,\fI3\/\fB+\fR.
561
562 The valid range for numbers
563 .I first
564 and
565 .I step
566 is 1..65535.
567
568 An injection expression can contain only one
569 .BR error =
570 or
571 .BR retval =
572 specification.
573 If an injection expression contains multiple
574 .BR when =
575 specifications, the last one takes precedence.
576
577 Accounting of syscalls that are subject to injection
578 is done per syscall and per tracee.
579
580 Specification of syscall injection can be combined
581 with other syscall filtering options, for example,
582 \fB\-P \fI/dev/urandom \fB\-e inject\fR=\,\fIfile\/\fR:\fBerror\fR=\,\fIENOENT\fR.
583
584 .TP
585 \fB\-e\ fault\fR=\,\fIset\/\fR[:\fBerror\fR=\,\fIerrno\/\fR][:\fBwhen\fR=\,\fIexpr\/\fR]
586 Perform syscall fault injection for the specified set of syscalls.
587
588 This is equivalent to more generic
589 \fB\-e\ inject\fR= expression with default value of
590 .I errno
591 option set to
592 .IR ENOSYS .
593
594 .TP
595 .BI "\-P " path
596 Trace only system calls accessing
597 .IR path .
598 Multiple
599 .B \-P
600 options can be used to specify several paths.
601 .TP
602 .B \-v
603 Print unabbreviated versions of environment, stat, termios, etc.
604 calls.  These structures are very common in calls and so the default
605 behavior displays a reasonable subset of structure members.  Use
606 this option to get all of the gory details.
607 .SS Tracing
608 .TP 12
609 .BI "\-b " syscall
610 If specified syscall is reached, detach from traced process.
611 Currently, only
612 .I execve
613 syscall is supported.  This option is useful if you want to trace
614 multi-threaded process and therefore require -f, but don't want
615 to trace its (potentially very complex) children.
616 .TP
617 .B \-D
618 Run tracer process as a detached grandchild, not as parent of the
619 tracee.  This reduces the visible effect of
620 .B strace
621 by keeping the tracee a direct child of the calling process.
622 .TP
623 .B \-f
624 Trace child processes as they are created by currently traced
625 processes as a result of the
626 .BR fork (2),
627 .BR vfork (2)
628 and
629 .BR clone (2)
630 system calls.  Note that
631 .B \-p
632 .I PID
633 .B \-f
634 will attach all threads of process PID if it is multi-threaded,
635 not only thread with thread_id = PID.
636 .TP
637 .B \-ff
638 If the
639 .B \-o
640 .I filename
641 option is in effect, each processes trace is written to
642 .I filename.pid
643 where pid is the numeric process id of each process.
644 This is incompatible with
645 .BR \-c ,
646 since no per-process counts are kept.
647 .TP
648 .BI "\-I " interruptible
649 When strace can be interrupted by signals (such as pressing ^C).
650 1: no signals are blocked; 2: fatal signals are blocked while decoding syscall
651 (default); 3: fatal signals are always blocked (default if '-o FILE PROG');
652 4: fatal signals and SIGTSTP (^Z) are always blocked (useful to make
653 strace -o FILE PROG not stop on ^Z).
654 .SS Startup
655 .TP 12
656 \fB\-E\ \fIvar\fR=\,\fIval\fR
657 Run command with
658 .IR var = val
659 in its list of environment variables.
660 .TP
661 .BI "\-E " var
662 Remove
663 .IR var
664 from the inherited list of environment variables before passing it on to
665 the command.
666 .TP
667 .BI "\-p " pid
668 Attach to the process with the process
669 .SM ID
670 .I pid
671 and begin tracing.
672 The trace may be terminated
673 at any time by a keyboard interrupt signal (\c
674 .SM CTRL\s0-C).
675 .B strace
676 will respond by detaching itself from the traced process(es)
677 leaving it (them) to continue running.
678 Multiple
679 .B \-p
680 options can be used to attach to many processes in addition to
681 .I command
682 (which is optional if at least one
683 .B \-p
684 option is given).
685 .B \-p
686 "`pidof PROG`" syntax is supported.
687 .TP
688 .BI "\-u " username
689 Run command with the user \s-1ID\s0, group \s-2ID\s0, and
690 supplementary groups of
691 .IR username .
692 This option is only useful when running as root and enables the
693 correct execution of setuid and/or setgid binaries.
694 Unless this option is used setuid and setgid programs are executed
695 without effective privileges.
696 .SS Miscellaneous
697 .TP 12
698 .B \-d
699 Show some debugging output of
700 .B strace
701 itself on the standard error.
702 .TP
703 .B \-F
704 This option is now obsolete and it has the same functionality as
705 .BR \-f .
706 .TP
707 .B \-h
708 Print the help summary.
709 .TP
710 .B \-V
711 Print the version number of
712 .BR strace .
713 .SH DIAGNOSTICS
714 When
715 .I command
716 exits,
717 .B strace
718 exits with the same exit status.
719 If
720 .I command
721 is terminated by a signal,
722 .B strace
723 terminates itself with the same signal, so that
724 .B strace
725 can be used as a wrapper process transparent to the invoking parent process.
726 Note that parent-child relationship (signal stop notifications,
727 getppid() value, etc) between traced process and its parent are not preserved
728 unless
729 .B \-D
730 is used.
731 .LP
732 When using
733 .B \-p
734 without a
735 .IR command ,
736 the exit status of
737 .B strace
738 is zero unless no processes has been attached or there was an unexpected error
739 in doing the tracing.
740 .SH "SETUID INSTALLATION"
741 If
742 .B strace
743 is installed setuid to root then the invoking user will be able to
744 attach to and trace processes owned by any user.
745 In addition setuid and setgid programs will be executed and traced
746 with the correct effective privileges.
747 Since only users trusted with full root privileges should be allowed
748 to do these things,
749 it only makes sense to install
750 .B strace
751 as setuid to root when the users who can execute it are restricted
752 to those users who have this trust.
753 For example, it makes sense to install a special version of
754 .B strace
755 with mode 'rwsr-xr--', user
756 .B root
757 and group
758 .BR trace ,
759 where members of the
760 .B trace
761 group are trusted users.
762 If you do use this feature, please remember to install
763 a non-setuid version of
764 .B strace
765 for ordinary lusers to use.
766 .SH NOTES
767 It is a pity that so much tracing clutter is produced by systems
768 employing shared libraries.
769 .LP
770 It is instructive to think about system call inputs and outputs
771 as data-flow across the user/kernel boundary.  Because user-space
772 and kernel-space are separate and address-protected, it is
773 sometimes possible to make deductive inferences about process
774 behavior using inputs and outputs as propositions.
775 .LP
776 In some cases, a system call will differ from the documented behavior
777 or have a different name.  For example, on System V-derived systems
778 the true
779 .BR time (2)
780 system call does not take an argument and the
781 .B stat
782 function is called
783 .B xstat
784 and takes an extra leading argument.  These
785 discrepancies are normal but idiosyncratic characteristics of the
786 system call interface and are accounted for by C library wrapper
787 functions.
788 .LP
789 Some system calls have different names in different architectures and
790 personalities.  In these cases, system call filtering and printing
791 uses the names that match corresponding
792 .BR __NR_ *
793 kernel macros of the tracee's architecture and personality.
794 There are two exceptions from this general rule:
795 .BR arm_fadvise64_64 (2)
796 ARM syscall and
797 .BR xtensa_fadvise64_64 (2)
798 Xtensa syscall are filtered and printed as
799 .BR fadvise64_64 (2).
800 .LP
801 On some platforms a process that is attached to with the
802 .B \-p
803 option may observe a spurious EINTR return from the current
804 system call that is not restartable.  (Ideally, all system calls
805 should be restarted on strace attach, making the attach invisible
806 to the traced process, but a few system calls aren't.
807 Arguably, every instance of such behavior is a kernel bug.)
808 This may have an unpredictable effect on the process
809 if the process takes no action to restart the system call.
810 .SH BUGS
811 Programs that use the
812 .I setuid
813 bit do not have
814 effective user
815 .SM ID
816 privileges while being traced.
817 .LP
818 A traced process runs slowly.
819 .LP
820 Traced processes which are descended from
821 .I command
822 may be left running after an interrupt signal (\c
823 .SM CTRL\s0-C).
824 .LP
825 The
826 .B \-i
827 option is weakly supported.
828 .SH HISTORY
829 The original
830 .B strace
831 was written by Paul Kranenburg
832 for SunOS and was inspired by its trace utility.
833 The SunOS version of
834 .B strace
835 was ported to Linux and enhanced
836 by Branko Lankester, who also wrote the Linux kernel support.
837 Even though Paul released
838 .B strace
839 2.5 in 1992,
840 Branko's work was based on Paul's
841 .B strace
842 1.5 release from 1991.
843 In 1993, Rick Sladkey merged
844 .B strace
845 2.5 for SunOS and the second release of
846 .B strace
847 for Linux, added many of the features of
848 .BR truss (1)
849 from SVR4, and produced an
850 .B strace
851 that worked on both platforms.  In 1994 Rick ported
852 .B strace
853 to SVR4 and Solaris and wrote the
854 automatic configuration support.  In 1995 he ported
855 .B strace
856 to Irix
857 and tired of writing about himself in the third person.
858 .SH REPORTING BUGS
859 Problems with
860 .B strace
861 should be reported to the
862 .B strace
863 mailing list at <strace\-devel@lists.sourceforge.net>.
864 .SH "SEE ALSO"
865 .BR ltrace (1),
866 .BR time (1),
867 .BR ptrace (2),
868 .BR proc (5)