12.2 Eliminating dtrace Interference

If you trace every call to the write() system call, it causes a cascade of output because each call causes the dtrace command to call write() as it displays the output, and so on. This feedback loop is a good example of how the dtrace command can interfere with the desired data. To prevent this type of unwanted data from being traced, use a simple predicate like the one that is shown in the following example and save it in a file named stringof.d:

/pid != $pid/
  printf("%s", stringof(copyin(arg1, arg2)));

In the previous example, the $pid macro variable expands to the process identifier of the process that enabled the probes. The pid variable contains the process identifier of the process whose thread was running on the CPU where the probe was fired. Therefore, the predicate /pid != $pid/ ensures that the script does not trace any events related to itself.