KTRACE(9)
π« KTRACE(9) β the process tracing kernel interface, bestie edition π«
okay so this is a page from the Kernel Developer's Manual β yes, the kernel developer's manual, we're in the big leagues now π«Ά β and it's all about ktrgenio, ktrnamei, ktrpsig, ktrsyscall, ktrsysret, and KTRPOINT, aka the process tracing kernel interface. buckle up, this one's for the kernel girlies π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/ktrace.h>
KTRPOINT(struct proc *p, int type);
void
ktrgenio(struct proc *p, int fd, enum uio_rw rw, struct iovec *iov,
int len, int error);
void
ktrnamei(struct proc *p, char *path);
void
ktrpsig(struct proc *p, int sig, sig_t action, int mask, int code,
siginfo_t *si);
void
ktrsyscall(struct proc *p, register_t code, size_t argsize,
register_t args[]);
void
ktrsysret(struct proc *p, register_t code, int error,
register_t retval);
like, look at all those includes. she's thriving πΈ
π DESCRIPTION π
so the whole vibe of this interface is: it exists for kernel subsystems and machine dependent code to keep the user in the loop about what's happening to a process β but only if tracing of that kind of event is actually turned on, which you do with the ktrace(2) system call β. every one of these functions (except KTRPOINT, she's special, main character energy π) handles one specific type of event, and here's the breakdown:
KTRPOINT()β this macro. bestie. use her before you call any of the other tracing functions, because she's the vibe check that confirms tracing for that particular kind of event is even enabled β .typehas to be aKTR_value that lines up with aKTRFAC_value described over inktrace(2).ktrgenio()β call this one for every generic input/output transaction. she takes thefdfile descriptor, therwtransaction type (go peek atsys/sys/uio.hfor theenum uio_rwdefinition π), theiovinput/output data vector,lenwhich is the size of theiovvector, and finallyerror, the status of the transaction. that's the whole squad right there πktrnamei()β call her every single time anamei(9)operation gets performed over thepathname. every. time. no cap π¦ktrpsig()β call this for each signalsigposted for the traced process. theactiontaken is one ofSIG_DFL,SIG_IGN, orSIG_ERR, exactly as described in thesigaction(2)document.maskis the current traced process' signal mask. the signal-specific code and thesiginfo_tstructure (as described in<sys/siginfo.h>) get passed in through thecodeandsiarguments respectively. she's giving very thorough πktrsyscall()β call her for each system call numbercodethat gets executed, with the arguments inargs, total count ofargsize. π₯ktrsysret()β call her on the return from each system call numbercode, with the error number inerror(as described inerrno(2)) and a return value inretvalthat's syscall dependent β so like, don't come for her ifretvallooks different every time, that's literally the point π
π CODE REFERENCES π
the process tracing facility is implemented in sys/kern/kern_ktrace.c. go read it, iykyk π
π SEE ALSO π
the whole friend group, love that for them π«Ά
π HISTORY π
the process tracing facility first appeared in 4.3BSD-Reno. iconic behavior, honestly π
and the ktrace section manual page appeared in OpenBSD 3.4. slay π
mwah β this page came to you from Debian, dated December 13, 2023. go trace some processes, bestie, you've got this π¦β¨
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2003 Michael Shalayeff
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms