1STRACE(1)                   General Commands Manual                  STRACE(1)
2
3
4

NAME

6       strace - trace system calls and signals
7

SYNOPSIS

9       strace  [-CdffhiqrtttTvVxxy]  [-In]  [-bexecve] [-eexpr]...  [-acolumn]
10       [-ofile]  [-sstrsize]  [-Ppath]...  -ppid...  /  [-D]  [-Evar[=val]]...
11       [-uusername] command [args]
12
13       strace  -c[df]  [-In]  [-bexecve]  [-eexpr]...  [-Ooverhead] [-Ssortby]
14       -ppid... / [-D] [-Evar[=val]]... [-uusername] command [args]
15

DESCRIPTION

17       In the simplest case strace runs the specified command until it  exits.
18       It  intercepts  and  records  the  system  calls  which are called by a
19       process and the signals which are received by a process.  The  name  of
20       each  system  call,  its  arguments and its return value are printed on
21       standard error or to the file specified with the -o option.
22
23       strace is a useful diagnostic, instructional, and debugging tool.  Sys‐
24       tem  administrators,  diagnosticians  and trouble-shooters will find it
25       invaluable for solving problems with programs for which the  source  is
26       not  readily available since they do not need to be recompiled in order
27       to trace them.  Students, hackers and the overly-curious will find that
28       a  great  deal  can  be  learned about a system and its system calls by
29       tracing even ordinary programs.  And programmers will find  that  since
30       system  calls  and  signals  are  events that happen at the user/kernel
31       interface, a close examination of this boundary is very useful for  bug
32       isolation, sanity checking and attempting to capture race conditions.
33
34       Each  line  in the trace contains the system call name, followed by its
35       arguments in parentheses and its return value.  An example from  strac‐
36       ing the command ``cat /dev/null'' is:
37
38       open("/dev/null", O_RDONLY) = 3
39
40       Errors (typically a return value of -1) have the errno symbol and error
41       string appended.
42
43       open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
44
45       Signals are printed as a signal symbol and a signal string.  An excerpt
46       from stracing and interrupting the command ``sleep 666'' is:
47
48       sigsuspend([] <unfinished ...>
49       --- SIGINT (Interrupt) ---
50       +++ killed by SIGINT +++
51
52       If  a  system call is being executed and meanwhile another one is being
53       called from a different thread/process then strace will try to preserve
54       the  order  of  those  events and mark the ongoing call as being unfin‐
55       ished.  When the call returns it will be marked as resumed.
56
57       [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...>
58       [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
59       [pid 28772] <... select resumed> )      = 1 (in [3])
60
61       Interruption of a (restartable) system call by  a  signal  delivery  is
62       processed  differently  as  kernel  terminates the system call and also
63       arranges its immediate reexecution after the signal handler completes.
64
65       read(0, 0x7ffff72cf5cf, 1)              = ? ERESTARTSYS (To be restarted)
66       --- SIGALRM (Alarm clock) @ 0 (0) ---
67       rt_sigreturn(0xe)                       = 0
68       read(0, ""..., 1)                       = 0
69
70       Arguments are printed in symbolic form with a  passion.   This  example
71       shows the shell performing ``>>xyzzy'' output redirection:
72
73       open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
74
75       Here  the  third  argument of open is decoded by breaking down the flag
76       argument into its three bitwise-OR constituents and printing  the  mode
77       value in octal by tradition.  Where traditional or native usage differs
78       from ANSI or POSIX, the latter forms are  preferred.   In  some  cases,
79       strace output has proven to be more readable than the source.
80
81       Structure  pointers  are  dereferenced and the members are displayed as
82       appropriate.  In all cases arguments are formatted in the  most  C-like
83       fashion  possible.   For  example,  the  essence of the command ``ls -l
84       /dev/null'' is captured as:
85
86       lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
87
88       Notice how the `struct stat' argument is dereferenced and how each mem‐
89       ber  is displayed symbolically.  In particular, observe how the st_mode
90       member is carefully decoded into a bitwise-OR of symbolic  and  numeric
91       values.   Also  notice in this example that the first argument to lstat
92       is an input to the system call and the second argument  is  an  output.
93       Since output arguments are not modified if the system call fails, argu‐
94       ments may not always be dereferenced.  For example, retrying  the  ``ls
95       -l'' example with a non-existent file produces the following line:
96
97       lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory)
98
99       In this case the porch light is on but nobody is home.
100
101       Character  pointers  are  dereferenced  and printed as C strings.  Non-
102       printing characters in strings are normally represented by  ordinary  C
103       escape  codes.  Only the first strsize (32 by default) bytes of strings
104       are printed; longer strings have an  ellipsis  appended  following  the
105       closing  quote.   Here  is  a  line  from  ``ls -l'' where the getpwuid
106       library routine is reading the password file:
107
108       read(3, "root::0:0:System Administrator:/"..., 1024) = 422
109
110       While structures are annotated using curly braces, simple pointers  and
111       arrays  are  printed  using square brackets with commas separating ele‐
112       ments.  Here is an example from the command ``id''  on  a  system  with
113       supplementary group ids:
114
115       getgroups(32, [100, 0]) = 2
116
117       On  the  other  hand, bit-sets are also shown using square brackets but
118       set elements are separated only by a space.  Here is the shell  prepar‐
119       ing to execute an external command:
120
121       sigprocmask(SIG_BLOCK, [CHLD TTOU], []) = 0
122
123       Here the second argument is a bit-set of two signals, SIGCHLD and SIGT‐
124       TOU.  In some cases the bit-set is so full that printing out the  unset
125       elements  is more valuable.  In that case, the bit-set is prefixed by a
126       tilde like this:
127
128       sigprocmask(SIG_UNBLOCK, ~[], NULL) = 0
129
130       Here the second argument represents the full set of all signals.
131

OPTIONS

133       -c          Count time, calls, and errors for each  system  call
134                   and  report  a  summary  on program exit.  On Linux,
135                   this attempts to show system time  (CPU  time  spent
136                   running  in  the  kernel)  independent of wall clock
137                   time.  If -c is used with -f  or  -F  (below),  only
138                   aggregate totals for all traced processes are kept.
139
140       -C          Like  -c  but  also  print regular output while pro‐
141                   cesses are running.
142
143       -D          Run tracer process as a detached grandchild, not  as
144                   parent  of  the  tracee.   This  reduces the visible
145                   effect of strace by  keeping  the  tracee  a  direct
146                   child of the calling process.
147
148       -d          Show  some  debugging output of strace itself on the
149                   standard error.
150
151       -f          Trace child processes as they are  created  by  cur‐
152                   rently  traced processes as a result of the fork(2),
153                   vfork(2) and clone(2) system calls. Note that -p PID
154                   -f  will  attach all threads of process PID if it is
155                   multi-threaded, not only  thread  with  thread_id  =
156                   PID.
157
158       -ff         If  the  -o  filename option is in effect, each pro‐
159                   cesses trace is written to filename.pid where pid is
160                   the  numeric  process  id  of each process.  This is
161                   incompatible with -c, since  no  per-process  counts
162                   are kept.
163
164       -F          This  option  is  now  obsolete  and it has the same
165                   functionality as -f.
166
167       -h          Print the help summary.
168
169       -i          Print the instruction pointer at  the  time  of  the
170                   system call.
171
172       -q          Suppress  messages  about  attaching, detaching etc.
173                   This happens automatically when output is redirected
174                   to a file and the command is run directly instead of
175                   attaching.
176
177       -qq         If given twice, suppress messages about process exit
178                   status.
179
180       -r          Print a relative timestamp upon entry to each system
181                   call.  This records the time difference between  the
182                   beginning of successive system calls.
183
184       -t          Prefix each line of the trace with the time of day.
185
186       -tt         If  given  twice,  the time printed will include the
187                   microseconds.
188
189       -ttt        If given thrice, the time printed will  include  the
190                   microseconds and the leading portion will be printed
191                   as the number of seconds since the epoch.
192
193       -T          Show the time spent in system  calls.  This  records
194                   the  time  difference  between the beginning and the
195                   end of each system call.
196
197       -v          Print unabbreviated versions of  environment,  stat,
198                   termios,  etc.   calls.   These  structures are very
199                   common in calls and so the default behavior displays
200                   a  reasonable subset of structure members.  Use this
201                   option to get all of the gory details.
202
203       -V          Print the version number of strace.
204
205       -x          Print all non-ASCII strings  in  hexadecimal  string
206                   format.
207
208       -xx         Print all strings in hexadecimal string format.
209
210       -y          Print  paths  associated  with file descriptor argu‐
211                   ments.
212
213       -a column   Align return values in a  specific  column  (default
214                   column 40).
215
216       -b syscall  If  specified syscall is reached, detach from traced
217                   process.  Currently, only  execve  syscall  is  sup‐
218                   ported.  This  option is useful if you want to trace
219                   multi-threaded process and therefore require -f, but
220                   don't  want  to trace its (potentially very complex)
221                   children.
222
223       -e expr     A qualifying expression which modifies which  events
224                   to  trace  or  how to trace them.  The format of the
225                   expression is:
226
227                             [qualifier=][!]value1[,value2]...
228
229                   where qualifier is one of  trace,  abbrev,  verbose,
230                   raw,  signal,  read,  or write and value is a quali‐
231                   fier-dependent symbol or number.  The default quali‐
232                   fier  is  trace.   Using an exclamation mark negates
233                   the set of values.  For example, -e open means  lit‐
234                   erally  -e trace=open which in turn means trace only
235                   the open system call.  By  contrast,  -e trace=!open
236                   means  to  trace  every system call except open.  In
237                   addition, the special values all and none  have  the
238                   obvious meanings.
239
240                   Note  that some shells use the exclamation point for
241                   history expansion even inside quoted arguments.   If
242                   so,  you  must  escape  the exclamation point with a
243                   backslash.
244
245       -e trace=set
246                   Trace only the specified set of system  calls.   The
247                   -c  option  is  useful  for determining which system
248                   calls  might  be  useful  to  trace.   For  example,
249                   trace=open,close,read,write   means  to  only  trace
250                   those four system calls.   Be  careful  when  making
251                   inferences  about the user/kernel boundary if only a
252                   subset of system calls  are  being  monitored.   The
253                   default is trace=all.
254
255       -e trace=file
256                   Trace  all system calls which take a file name as an
257                   argument.  You can think of this as an  abbreviation
258                   for  -e trace=open,stat,chmod,unlink,...   which  is
259                   useful to seeing what files the process is referenc‐
260                   ing.    Furthermore,  using  the  abbreviation  will
261                   ensure that you don't accidentally forget to include
262                   a  call like lstat in the list.  Betchya woulda for‐
263                   got that one.
264
265       -e trace=process
266                   Trace all system calls which involve process manage‐
267                   ment.   This  is useful for watching the fork, wait,
268                   and exec steps of a process.
269
270       -e trace=network
271                   Trace all the network related system calls.
272
273       -e trace=signal
274                   Trace all signal related system calls.
275
276       -e trace=ipc
277                   Trace all IPC related system calls.
278
279       -e trace=desc
280                   Trace all file descriptor related system calls.
281
282       -e trace=memory
283                   Trace all memory mapping related system calls.
284
285       -e abbrev=set
286                   Abbreviate the output from printing each  member  of
287                   large  structures.   The default is abbrev=all.  The
288                   -v option has the effect of abbrev=none.
289
290       -e verbose=set
291                   Dereference structures for the specified set of sys‐
292                   tem calls.  The default is verbose=all.
293
294       -e raw=set  Print raw, undecoded arguments for the specified set
295                   of system calls.  This  option  has  the  effect  of
296                   causing  all arguments to be printed in hexadecimal.
297                   This is mostly useful if you don't trust the  decod‐
298                   ing  or you need to know the actual numeric value of
299                   an argument.
300
301       -e signal=set
302                   Trace only the specified  subset  of  signals.   The
303                   default is signal=all.  For example, signal =! SIGIO
304                   (or signal=!io)  causes  SIGIO  signals  not  to  be
305                   traced.
306
307       -e read=set Perform a full hexadecimal and ASCII dump of all the
308                   data read from file descriptors listed in the speci‐
309                   fied set.  For example, to see all input activity on
310                   file descriptors 3 and 5 use -e read=3,5.  Note that
311                   this  is  independent from the normal tracing of the
312                   read(2) system  call  which  is  controlled  by  the
313                   option -e trace=read.
314
315       -e write=set
316                   Perform a full hexadecimal and ASCII dump of all the
317                   data written to file descriptors listed in the spec‐
318                   ified  set.  For example, to see all output activity
319                   on file descriptors 3 and 5 use -e write=3,5.   Note
320                   that  this is independent from the normal tracing of
321                   the write(2) system call which is controlled by  the
322                   option -e trace=write.
323
324       -I interruptible
325                   When  strace  can be interrupted by signals (such as
326                   pressing ^C).  1: no signals are blocked;  2:  fatal
327                   signals   are   blocked   while   decoding   syscall
328                   (default);  3:  fatal  signals  are  always  blocked
329                   (default  if  '-o  FILE PROG'); 4: fatal signals and
330                   SIGTSTP (^Z) are  always  blocked  (useful  to  make
331                   strace -o FILE PROG not stop on ^Z).
332
333       -o filename Write  the  trace output to the file filename rather
334                   than to stderr.  Use filename.pid if  -ff  is  used.
335                   If the argument begins with `|' or with `!' then the
336                   rest of the argument is treated as a command and all
337                   output  is piped to it.  This is convenient for pip‐
338                   ing  the  debugging  output  to  a  program  without
339                   affecting the redirections of executed programs.
340
341       -O overhead Set  the  overhead for tracing system calls to over‐
342                   head microseconds.  This is  useful  for  overriding
343                   the  default heuristic for guessing how much time is
344                   spent in mere measuring  when  timing  system  calls
345                   using  the -c option.  The accuracy of the heuristic
346                   can be gauged by timing a given program run  without
347                   tracing  (using  time(1))  and comparing the accumu‐
348                   lated system call time to the total  produced  using
349                   -c.
350
351       -p pid      Attach  to  the  process with the process ID pid and
352                   begin tracing.  The trace may be terminated  at  any
353                   time   by  a  keyboard  interrupt  signal  (CTRL-C).
354                   strace will respond by  detaching  itself  from  the
355                   traced  process(es)  leaving  it  (them) to continue
356                   running.  Multiple -p options can be used to  attach
357                   to many processes.  -p "`pidof PROG`" syntax is sup‐
358                   ported.
359
360       -P path     Trace only system calls accessing path.  Multiple -P
361                   options can be used to specify several paths.
362
363       -s strsize  Specify  the  maximum  string  size  to  print  (the
364                   default is 32).  Note that filenames are not consid‐
365                   ered strings and are always printed in full.
366
367       -S sortby   Sort  the  output of the histogram printed by the -c
368                   option by the specified criterion.  Legal values are
369                   time, calls, name, and nothing (default is time).
370
371       -u username Run  command with the user ID, group ID, and supple‐
372                   mentary groups of username.   This  option  is  only
373                   useful  when running as root and enables the correct
374                   execution of setuid and/or setgid binaries.   Unless
375                   this  option  is used setuid and setgid programs are
376                   executed without effective privileges.
377
378       -E var=val  Run command with var=val in its list of  environment
379                   variables.
380
381       -E var      Remove  var  from  the inherited list of environment
382                   variables before passing it on to the command.
383

DIAGNOSTICS

385       When command exits, strace exits with the same exit status.   If
386       command is terminated by a signal, strace terminates itself with
387       the same signal, so that strace can be used as a wrapper process
388       transparent to the invoking parent process.
389
390       When  using  -p,  the exit status of strace is zero unless there
391       was an unexpected error in doing the tracing.
392

SETUID INSTALLATION

394       If strace is installed setuid to root  then  the  invoking  user
395       will be able to attach to and trace processes owned by any user.
396       In addition setuid and setgid  programs  will  be  executed  and
397       traced  with the correct effective privileges.  Since only users
398       trusted with full root privileges should be allowed to do  these
399       things,  it only makes sense to install strace as setuid to root
400       when the users who can execute it are restricted to those  users
401       who  have  this trust.  For example, it makes sense to install a
402       special version of strace with mode `rwsr-xr--', user  root  and
403       group trace, where members of the trace group are trusted users.
404       If you do use this feature, please remember to  install  a  non-
405       setuid version of strace for ordinary lusers to use.
406

SEE ALSO

408       ltrace(1), time(1), ptrace(2), proc(5)
409

NOTES

411       It is a pity that so much tracing clutter is produced by systems
412       employing shared libraries.
413
414       It is instructive to think about system call inputs and  outputs
415       as  data-flow  across  the  user/kernel boundary.  Because user-
416       space and kernel-space are separate and address-protected, it is
417       sometimes  possible  to  make deductive inferences about process
418       behavior using inputs and outputs as propositions.
419
420       In some cases, a system call will  differ  from  the  documented
421       behavior  or  have  a different name.  For example, on System V-
422       derived systems the true time(2) system call does  not  take  an
423       argument  and  the  stat  function  is called xstat and takes an
424       extra leading argument.   These  discrepancies  are  normal  but
425       idiosyncratic  characteristics  of the system call interface and
426       are accounted for by C library wrapper functions.
427
428       On some platforms a process that has a system call trace applied
429       to  it  with  the -p option will receive a SIGSTOP.  This signal
430       may interrupt a system call that is not restartable.   This  may
431       have an unpredictable effect on the process if the process takes
432       no action to restart the system call.
433

BUGS

435       Programs that use the setuid bit do not have effective  user  ID
436       privileges while being traced.
437
438       A traced process runs slowly.
439
440       Traced  processes  which  are descended from command may be left
441       running after an interrupt signal (CTRL-C).
442
443       The -i option is weakly supported.
444

HISTORY

446       strace The original strace was written by  Paul  Kranenburg  for
447       SunOS  and was inspired by its trace utility.  The SunOS version
448       of strace was ported to Linux and enhanced by Branko  Lankester,
449       who  also  wrote  the  Linux  kernel  support.  Even though Paul
450       released strace 2.5 in 1992, Branko's work was based  on  Paul's
451       strace  1.5  release  from  1991.   In 1993, Rick Sladkey merged
452       strace 2.5 for SunOS and the second release of strace for Linux,
453       added  many  of the features of truss(1) from SVR4, and produced
454       an strace that worked on both platforms.  In  1994  Rick  ported
455       strace to SVR4 and Solaris and wrote the automatic configuration
456       support.  In 1995 he ported strace to Irix and tired of  writing
457       about himself in the third person.
458

PROBLEMS

460       Problems  with  strace  should be reported to the strace mailing
461       list at <strace-devel@lists.sourceforge.net>.
462
463
464
465                                  2010-03-30                         STRACE(1)
Impressum