KTRACE(1) FreeBSD General Commands Manual KTRACE(1)


ktraceenable kernel process tracing


ktrace [ -aCcdi][ -f trfile][ -g pgrp | -p pid][ -t trstr]

ktrace [ -adi][ -f trfile][ -t trstr] command


The ktrace utility enables kernel trace logging for the specified processes. Kernel trace data is logged to the file ktrace.out. The kernel operations that are traced include system calls, namei translations, signal processing, and I/O.

Once tracing is enabled on a process, trace data will be logged until either the process exits or the trace point is cleared. A traced process can generate enormous amounts of log data quickly; It is strongly suggested that users memorize how to disable tracing before attempting to trace a process. The following command is sufficient to disable tracing on all user-owned processes, and, if executed by root, all processes:

$ ktrace -C

The trace file is not human readable; use kdump(1) to decode it.

The utility may be used only with a kernel that has been built with the “KTRACE” option in the kernel configuration file.

The options are:

Append to the trace file instead of recreating it.
Disable tracing on all user-owned processes, and, if executed by root, all processes in the system.
Clear the specified trace points associated with the given file or processes.
Descendants; perform the operation for all current children of the designated processes.
-f trfile
Log trace records to trfile instead of ktrace.out.
-g pgid
Enable (disable) tracing on all processes in the process group (only one -g flag is permitted).
Inherit; pass the trace flags to all future children of the designated processes.
-p pid
Enable (disable) tracing on the indicated process id (only one -p flag is permitted).
-t trstr
Specify the list of trace points to enable or disable, one per letter. If an explicit list is not specified, the default set of trace points is used.

The following trace points are supported:

trace system calls
trace page faults
trace I/O
trace namei translations
trace capability check failures
trace signal processing
trace various structures
userland traces
context switches
trace sysctl(3) requests
trace the default set of trace points - c, i, n, p, s, t, u, y
Execute command with the specified trace flags.

The -p, -g, and command options are mutually exclusive.


# trace all kernel operations of process id 34
$ ktrace -p 34

# trace all kernel operations of processes in process group 15 and # pass the trace flags to all current and future children

$ ktrace -idg 15

# disable all tracing of process 65

$ ktrace -cp 65

# disable tracing signals on process 70 and all current children

$ ktrace -t s -cdp 70

# enable tracing of I/O on process 67

$ ktrace -ti -p 67

# run the command "w", tracing only system calls

$ ktrace -tc w

# disable all tracing to the file "tracedata"

$ ktrace -c -f tracedata

# disable tracing of all user-owned processes

$ ktrace -C




The ktrace command appeared in 4.4BSD.


Only works if trfile is a regular file.
August 26, 2014 FreeBSD