2.12.2 Pointers to Structs

Referring to structs by using pointers is very common in C and D. You can use the operator -> to access struct members through a pointer. If struct s has a member m, and you have a pointer to this struct named sp, where sp is a variable of type struct s *, you can either use the * operator to first dereference the sp pointer to access the member:

struct s *sp;

Or, you can use the -> operator as shorthand for this notation. The following two D fragments are equivalent if sp is a pointer to a struct:


DTrace provides several built-in variables that are pointers to structs. For example, the pointer curpsinfo refers to struct psinfo and its content provides a snapshot of information about the state of the process associated with the thread that fired the current probe. The following table lists a few example expressions that use curpsinfo, including their types and their meanings.

Example Expression





Current process ID


char []

Executable file name


char []

Initial command-line arguments

For more information, see Section, “psinfo_t”.

The next example uses the pr_fname member to identify a process of interest. In an editor, type the following script and save it in a file named procfs.d:

/ curpsinfo->pr_fname == "date" /
  printf("%s run by UID %d\n", curpsinfo->pr_psargs, curpsinfo->pr_uid);

This clause uses the expression curpsinfo->pr_fname to access and match the command name so that the script selects the correct write() requests before tracing the arguments. Notice that by using operator == with a left-hand argument that is an array of char and a right-hand argument that is a string, the D compiler infers that the left-hand argument should be promoted to a string and a string comparison should be performed. Type the command dtrace -q -s procs.d in one shell and then type the date command several times in another shell. The output that is displayed by DTrace is similar to the following:

# dtrace -q -s procfs.d 
date  run by UID 500
/bin/date  run by UID 500
date -R  run by UID 500

Complex data structures are used frequently in C programs, so the ability to describe and reference structs from D also provides a powerful capability for observing the inner workings of the Oracle Linux operating system kernel and its system interfaces.