6 .Nd print process system calls and signals
16 utility shows one or more processes to be traced.
17 For each traced process,
19 prints the system calls the process makes and the signals
25 to be traced, and/or attach to one or more existing processes.
27 The utility will run until no processes are left to trace, or until the user
28 presses the interrupt key (typically Ctrl-C).
29 Pressing this key once will cause all attached processes to be detached, with
30 the hope that the command that was started will also terminate cleanly from the
32 Pressing the interrupt key once more kills the command that was started.
34 The following options are available:
35 .Bl -tag -width XoXfileXX
38 Attach automatically to forked child processes.
39 Child processes of the started command will be treated as attached processes,
40 in that upon Ctrl-C presses they will be detached rather than killed.
43 With this option, the tracing engine tries to reduce noise from call preemption
44 by first polling the process that was active last.
45 This should reduce in cleaner output, but may also cause a single process to be
46 scheduled repeatedly and thus cause starvation.
49 By default, the most structure fields are printed with their name.
50 This option enables printing of all available names, which also includes
51 system call parameter names.
52 This flag may be useful to figure out the meaning of a parameter, and for
53 automatic processing of the output.
56 Each system call, and each signal arriving outside a system call, will be
57 preceded by a line showing the process's current stack trace.
58 For signals blocked by the target process, the stack trace may not be
60 Stack traces may not be supported on all platforms.
63 By default, no timestamps are printed.
64 If this flag is given once, each line will be prefixed by the current time.
65 If this flag is given twice, the time will also include microseconds.
66 The printed timestamp corresponds to the time at which printing of the rest of
67 the line was initiated, which in the case of call resumption may not be the
68 same as the time that the system call was initiated.
71 If this flag is given once, numerical values will be printed instead of
73 In addition, if it is given twice, the addresses of structures will be printed
74 instead of their contents.
77 By default, the output will be terse, in that not all structure fields are
78 shown, and strings and arrays are not always printed in full.
79 If this flag is provided once, more and longer output will be printed.
80 If it is provided twice, the tracer will print as much as possible.
83 By default, the output is sent to standard error.
84 With this option, the output is written to the given
91 attach to an existing process with process ID
93 This option may be used multiple times.
94 When attaching to one or more processes this way, starting a command becomes
98 If the user presses the information key (typically Ctrl-T), the list of traced
99 process along with their current status will be printed.
101 System calls are printed with the following general output format:
102 .Bd -literal -offset indent
103 .Sy name Ns ( Ns Sy parameters Ns ) = Sy result
106 Other informational lines may be printed about the status of the process.
107 These lines typically start with an uppercase letter, while system calls
108 always start with a lowercase letter or an underscore.
109 The following example shows the tracer output for a program that prints its
111 .Bd -literal -offset indent
112 Tracing printuid (pid 12685)
114 getuid() = 0 (euid=1)
115 write(1, "My uid: 0\en", 10) = 10
117 Process exited normally with code 0
120 The first and last lines of the output provide status information about the
122 Some calls return multiple results; extended results are printed in parentheses
123 after the primary call result, typically in
124 .Va name Ns = Ns Va value
126 System calls that do not return on success, such as
128 are printed without the equals sign and result, unless they fail.
129 System call failure is printed according to POSIX conventions; that is, the
130 call is assumed to return -1 with the value of
132 printed in square brackets after it:
133 .Bd -literal -offset indent
134 setuid(0) = -1 [EPERM]
137 If a system call ends up in an IPC-level failure, the -1 value will be preceded
141 However, this string will be omitted if the system call itself is printed at
142 the IPC level (that is, as an
144 call), generally because
146 has no handler to print the actual system call.
148 Signals are printed as they arrive at the traced process, using two asterisks
149 on both side of the signal name.
150 Signals may arrive both during and outside the execution of a system call:
151 .Bd -literal -offset indent
152 read(3, ** SIGUSR1 ** &0xeffff867, 4096) = -1 [EINTR]
154 getpid() = 5278 (ppid=5277)
155 kill(5278, SIGTERM) = ** SIGTERM ** <..>
156 Process terminated from signal SIGTERM
159 Multiple signals may be printed consecutively.
160 The above example illustrates a few other important aspects of output
162 Some call parameters may be printed only after the system call returns, in
163 order to show their actual value.
166 call, this would be the bytes that were read.
167 Upon failure, no bytes were read, so the buffer pointer is printed instead.
168 Finally, if a call that is expected to return (here,
170 does not return before the process terminates, the line ends with a
173 This is an instance of call preemption; more about that later.
175 Pointers are printed with a
177 prefix, except for NULL, which is printed using its own name.
178 In general, named constants are used instead of numerical constants wherever
180 For pointers of which the address is not available, typically because its
181 contents are passed by value,
185 Data buffers are printed as double-quoted strings, using C-style character
186 escaping for nontextual bytes.
187 If either the verbosity level or a copy error prevents the whole data buffer
188 from being printed, two dots will be printed after the closing quote.
189 The same is done when printing a string buffer which does not have a null
190 termination byte within its range.
191 Path names are shown in full regardless of the verbosity level.
193 Structures are printed as a set of structure fields enclosed in curly brackets.
195 .Va name Ns = Ns Va value
196 format is used, unless printing names for that structure type would introduce
197 too much noise and the
200 For many structures, by default only a subset of their fields are printed.
203 entry is added at the end.
204 In some cases, an attempt is made to print only the most useful fields:
205 .Bd -literal -offset indent
206 stat("/etc/motd", {st_mode=S_IFREG|0755, st_size=747, ..}) = 0
207 stat("/dev/tty", {st_mode=S_IFCHR|0666, st_rdev=<5,0>, ..}) = 0
210 As shown in the above example, flag fields are printed as a combination of
211 named constants, separated by a
214 Any leftover numerical bits are printed at the end.
215 The example also shows the format in which major/minor pairs are printed for
217 This is a custom format; there are a few other custom formats throughout the
219 output which are supposed to be sufficiently self-explanatory (and rare).
221 Arrays are printed using square brackets.
222 .Bd -literal -offset indent
224 getdents(3, [..(45)], 4096) = 1824
225 getdents(3, [{d_name="."}, ..(+44)], 4096) = 1824
226 getdents(3, [], 4096) = 0
229 If the array contents are not printed as per the settings for the verbosity
230 level, a single pseudo-element shows how many actual elements were in the array
231 (the second line in the example).
232 If the number of printed elements is limited, a final pseudo-element shows how
233 many additional elements were not printed (the third line in the example).
234 If a copy error occurs while part of the array has been printed already, a
237 pseudo-element is printed; for immediate failure, the array's pointer is shown.
238 Empty arrays will be printed as
241 Bit sets are printed as arrays except with just a space and no comma as
242 bit separator, closely following the output format of
246 For signal sets in particular, an inverted bit set may be shown, thus printing
247 only the bits which are not set; such sets are prefixed with a
249 to the opening bracket:
250 .Bd -literal -offset indent
251 sigprocmask(SIG_SETMASK, ~[USR1 USR2], []) = 0
256 prefixes are omitted for brevity in this case.
258 When multiple processes are traced at once, each line will have a prefix that
259 shows the PID of the corresponding process.
260 When the number of processes drops to one again, one more line is prefixed with
261 the PID of the remaining process, but using a
266 .Bd -literal -offset indent
268 25813| Tracing test*F (pid 25813)
270 25812| waitpid(-1, &.., WNOHANG) = 0
272 25813| Process exited normally with code 1
273 25812' waitpid(-1, W_EXITED(1), WNOHANG) = 25813
275 Process exited normally with code 0
278 If a process is preempted while making a system call, the system call will
279 be shown as suspended with the
282 Later, when the system call is resumed, the output so far will be repeated,
283 either in full or (due to memory limitations) with
285 in its body, before the remaining part of the system call is printed.
286 This time, the line will have a
288 asterisk in its prefix, to indicate that this is not a new system call:
289 .Bd -literal -offset indent
290 25812| write(1, "test\en", 5) = <..>
292 25812|*write(1, "test\en", 5) = 5
297 prints three dashes on their own line whenever the process context (program
298 counter and/or stack pointer) is changed during a system call.
299 This feature intends to help identify blocks of code run from signal handlers.
300 The following example shows a SIGALRM signal handler being invoked.
301 .Bd -literal -offset indent
302 sigsuspend([]) = ** SIGALRM ** -1 [EINTR]
304 sigprocmask(SIG_SETMASK, ~[], [ALRM]) = 0
305 sigreturn({sc_mask=[], ..})
310 However, the three dashes are not printed when a signal handler is invoked
311 while the program is not in a system call, because the tracer does not see such
313 It is however also printed for successful
323 utility was written by
324 .An David van Moolenbroek
325 .Aq david@minix3.org .
327 While the utility aims to provide output for all system calls that can possibly
328 be made by user programs, output printers for a small number of rarely-used
329 structures and IOCTLs are still missing. In such cases, plain pointers will be
330 printed instead of actual contents.
332 A signal arrives at the tracing process when sent to the target process, even
333 when the target process is blocking the signal and will thus receive it later.
334 This is a limitation of the ptrace infrastructure, although it does ensure that
335 a target process is not able to block signals generated for tracing purposes.
336 The result is that signals are not always shown at the time that they are
337 taken in by the target process, and that stack traces for signals may be off.
339 Attaching to system services is currently not supported, due to limitations of
340 the ptrace infrastructure. The
342 utility will detect and safely detach from system services, though.