Use the $target
macro variable to create scripts that can be applied to a particular user process of interest that is selected on the dtrace command line using the
p
option or created using the
c
option. The D programs specified on the command line or using the
s
option are compiled after processes are created or grabbed and the $target
variable expands to the integer process-ID of the first such process. For example, the following D script could be used to determine the distribution of system calls executed by a particular subject process:
syscall:::entry /pid == $target/ { @[probefunc] = count(); }
To determine the number of system calls executed by the
date
(
1
)
command, save the script in the file syscall.d
and execute the following command:
# dtrace -s syscall.d -c date
dtrace: script 'syscall.d' matched 227 probes
Fri Jul 30 13:46:06 PDT 2004
dtrace: pid 109058 has exited
gtime 1
getpid 1
getrlimit 1
rexit 1
ioctl 1
resolvepath 1
read 1
stat 1
write 1
munmap 1
close 2
fstat64 2
setcontext 2
mmap 2
open 2
brk 4