1 .\" $NetBSD: ktrace.2,v 1.17 2004/05/13 10:20:58 wiz Exp $
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)ktrace.2 8.1 (Berkeley) 6/4/93
45 .Fn ktrace "const char *tracefile" "int ops" "int trpoints" "pid_t pid"
47 .Fn fktrace "int fd" "int ops" "int trpoints" "pid_t pid"
51 function enables or disables tracing of one or more processes.
52 Users may only trace their own processes.
53 Only the super-user can trace setuid or setgid programs.
57 gives the pathname of the file to be used for tracing.
58 The file must exist and be writable by the calling process.
59 All trace records are always appended to the file,
60 so the file must be truncated to zero length to discard
62 If tracing points are being disabled (see KTROP_CLEAR below),
67 then instead of passing a filename as
69 a file descriptor is passed as
71 and behaviour is otherwise the same.
75 parameter specifies the requested ktrace operation.
76 The defined operations are:
77 .Bl -column KTRFLAG_DESCENDXXX -offset indent
78 .It KTROP_SET Enable trace points specified in Ar trpoints .
79 .It KTROP_CLEAR Disable trace points specified in Ar trpoints .
80 .It KTROP_CLEARFILE Stop all tracing.
81 .It KTRFLAG_DESCEND The tracing change should apply to the
82 specified process and all its current children.
87 parameter specifies the trace points of interest.
88 The defined trace points are:
89 .Bl -column KTRFAC_SYSCALLXXX -offset indent
90 .It KTRFAC_SYSCALL Trace system calls.
91 .It KTRFAC_SYSRET Trace return values from system calls.
92 .It KTRFAC_NAMEI Trace name lookup operations.
93 .It KTRFAC_GENIO Trace all I/O (note that this option can
94 generate much output).
95 .It KTRFAC_PSIG Trace posted signals.
96 .It KTRFAC_CSW Trace context switch points.
97 .It KTRFAC_EMUL Trace emulation changes.
98 .It KTRFAC_INHERIT Inherit tracing to future children.
101 Each tracing event outputs a record composed of a generic header
102 followed by a trace point specific structure.
103 The generic header is:
106 int ktr_len; /* length of buf */
107 short ktr_type; /* trace record type */
108 pid_t ktr_pid; /* process id */
109 char ktr_comm[MAXCOMLEN+1]; /* command name */
110 struct timeval ktr_time; /* timestamp */
117 field specifies the length of the
119 data that follows this header.
124 fields specify the process and command generating the record.
127 field gives the time (with microsecond resolution)
128 that the record was generated.
131 is an internal kernel pointer and is not useful.
133 The generic header is followed by
138 The type specific records are defined in the
139 .Pa \*[Lt]sys/ktrace.h\*[Gt]
142 On successful completion a value of 0 is returned.
143 Otherwise, a value of \-1 is returned and
145 is set to show the error.
149 .Bl -tag -width ENAMETOOLONGAA
151 A component of the path prefix is not a directory.
153 The pathname contains a character with the high-order bit set.
154 .It Bq Er ENAMETOOLONG
155 A component of a pathname exceeded 255 characters,
156 or an entire path name exceeded 1023 characters.
158 The named tracefile does not exist.
160 Search permission is denied for a component of the path prefix.
162 Too many symbolic links were encountered in translating the pathname.
164 An I/O error occurred while reading from or writing to the file system.
172 function call first appeared in