DTRACE_PROC(4)

πŸ’– DTRACE_PROC(4) β€” the dtrace_proc manual, but make it make sense πŸ’–

okay bestie, you found DTRACE_PROC(4) in the Kernel Interfaces Manual and you're like "what is this" β€” don't worry, I got you. this is the page for dtrace_proc, and by the end you're gonna be obsessed, fr fr. πŸ¦‹


✨ NAME ✨

dtrace_proc β€” a DTrace provider for tracing events related to user processes


πŸŽ€ SYNOPSIS πŸŽ€

proc:::create(struct proc *, struct proc *, int);

proc:::exec(char *);

proc:::exec-failure(int);

proc:::exec-success(char *);

proc:::exit(int);

proc:::signal-clear(int, ksiginfo_t *);

proc:::signal-discard(struct thread *, struct proc *, int);

proc:::signal-send(struct thread *, struct proc *, int);

🌸 DESCRIPTION 🌸

The DTrace proc provider gives you insight into events related to user processes: process and thread creation and termination events, and process signalling. it's giving "I see everything your processes are doing" and honestly? iconic. πŸ‘‘

The proc:::create() probe fires when a user process is created via the fork(2), vfork(2), pdfork(2), or rfork(2) system calls. lowkey important: kernel processes created with the kproc(9) KPI will not trigger this probe. no cap. πŸ™ˆ

  • the first two arguments are the new child process and its parent, respectively
  • the third argument is a mask of rfork(2) flags indicating which process resources are to be shared between the parent and child processes

The proc:::exec() probe fires when a process attempts to execute a file. its argument is the specified filename for the file. if the attempt fails because of an error, the proc:::exec-failure() probe will subsequently fire, providing the corresponding errno(2) value in its first argument. otherwise, the proc:::exec-success() probe will fire. slay, one or the other, never both. ✨

The proc:::exit() probe fires when a process exits or is terminated. its argument is the corresponding SIGCHLD signal code; valid values are documented in the siginfo(3) manual page and defined in signal.h. for example, when a process exits normally, the value of args[0] will be CLD_EXITED.

The proc:::signal-send() probe fires when a signal is about to be sent to a process. the proc:::signal-discard() probe fires when a signal is sent to a process that ignores it. heads up: this probe will fire after the proc:::signal-send() probe for the signal in question. the arguments to these probes are the thread and process to which the signal will be sent, and the signal number of the signal. valid signal numbers are defined in the signal(3) manual page.

The proc:::signal-clear() probe fires when a pending signal has been cleared by one of the sigwait(2), sigtimedwait(2), or sigwaitinfo(2) system calls. its arguments are the signal number of the cleared signal, and a pointer to the corresponding signal information. the siginfo_t for the signal can be obtained from args[1]->ksi_info. the way that is so specific and useful… we love to see it. πŸ’…


πŸ’œ ARGUMENTS πŸ’œ

so, though the proc provider probes use native FreeBSD argument types, standard D types for processes and threads are available. these are psinfo_t and lwpsinfo_t respectively, and are defined in /usr/lib/dtrace/psinfo.d. this file also defines two global variables, curpsinfo and curlwpsinfo, which provide representations of the current process and thread using these types. 🫢

🧚 the fields of psinfo_t are:

  • int pr_nlwp β€” number of threads in the process.
  • pid_t pr_pid β€” process ID.
  • pid_t pr_ppid β€” process ID of the parent process, or 0 if the process does not have a parent.
  • pid_t pr_pgid β€” process ID of the process group leader.
  • pid_t pr_sid β€” session ID, or 0 if the process does not belong to a session.
  • pid_t pr_uid β€” real user ID.
  • pid_t pr_euid β€” effective user ID.
  • pid_t pr_gid β€” real group ID.
  • pid_t pr_egid β€” effective group ID.
  • uintptr_t pr_addr β€” pointer to the struct proc for the process.
  • string pr_psargs β€” process arguments.
  • u_int pr_arglen β€” length of the process argument string.
  • u_int pr_jailid β€” jail ID of the process.

πŸ¦‹ the fields of lwpsinfo_t are:

  • id_t pr_lwpid β€” thread ID.
  • int pr_flag β€” thread flags.
  • int pr_pri β€” real scheduling priority of the thread.
  • char pr_state β€” currently always 0.
  • char pr_sname β€” currently always β€˜β€™?.
  • short pr_syscall β€” currently always 0.
  • uintptr_t pr_addr β€” pointer to the struct thread for the thread.
  • uintptr_t pr_wchan β€” current wait address on which the thread is sleeping.

🌈 FILES 🌈

  • /usr/lib/dtrace/psinfo.d β€” DTrace type and translator definitions for the proc provider.

⭐ EXAMPLES ⭐

the following script logs process execution events as they occur. it's short, it's cute, it works:

#pragma D option quiet

proc:::exec-success
{
        printf("%s", curpsinfo->pr_psargs);
}
wait, bestie, read this before you ship it: note that the pr_psargs field is subject to the limit defined by the kern.ps_arg_cache_limit sysctl. in particular, processes with an argument list longer than the value defined by this sysctl cannot be logged in this way. 😭 so if your args are huge, this ain't it.

πŸ’€ COMPATIBILITY πŸ’€

the proc provider in FreeBSD is not compatible with the proc provider in Solaris. not even a little. in particular, FreeBSD uses the native struct proc and struct thread types for probe arguments rather than translated types. additionally, a number of proc provider probes found in Solaris are not currently available on FreeBSD. so don't copy-paste your Solaris scripts and expect main character energy. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

dtrace(1), errno(2), fork(2), pdfork(2), rfork(2), vfork(2), siginfo(3), signal(3), dtrace_sched(4), kproc(9)


πŸŽ€ HISTORY πŸŽ€

The proc provider first appeared in FreeBSD 7.1.


πŸ’– AUTHORS πŸ’–

This manual page was written by Mark Johnston <markj@FreeBSD.org>.


okay periodt, that's the whole page, you ate it. πŸ’…βœ¨ this one came from the Debian manual set, dated April 17, 2016 β€” so if you're citing it, that's your source and date, bestie. go forth and trace those processes, you've got this. πŸ¦‹πŸŒΈπŸ’œ

πŸ“¦ where this page comes from