23.12.2018

The Advent of Void: Day 23: extrace

Today’s tool is extrace(1), a small, simple and powerful tool to trace program executions. By default extrace(1) will look at system wide executions, alternatively it can start a new process or start looking for executions in child processes of a specified pid. The output is a tree like structure including the process id, the command and its arguments, additional flags can add the environment of the process, the executing user or even the exit status and runtime duration.

The following example is the truncated extrace(1) output of checking the dhcpcd(8) man page and then executing dhcpcd -k to release all interfaces followed by executions from dhcpcd hooks.

$ extrace 911 man dhcpcd 912 less -T /tmp/man.XXXXH357hT /tmp/man.XXXXEOs5Na 930 doas dhcpcd -k 930 dhcpcd -k 932 /bin/sh /usr/libexec/dhcpcd-run-hooks 933 rm -f /run/dhcpcd/resolv.conf/br0.ra 936 sed -n 's/^domain //p' br0.dhcp 938 sed -n 's/^search //p' br0.dhcp 941 sed -n 's/^nameserver //p' br0.dhcp 943 cat /etc/resolv.conf.head 944 cmp -s /etc/resolv.conf /run/dhcpcd/resolv.conf.br0.ra 945 cat /run/dhcpcd/resolv.conf.br0.ra 946 rm -f /run/dhcpcd/resolv.conf.br0.ra 947 chmod 644 /etc/resolv.conf 948 rm -f /run/dhcpcd/resolv.conf.br0.ra 950 sed '/^# Generated by dhcpcd/,/^# End of dhcpcd/d' /etc/ntpd.conf 951 cmp -s /etc/ntpd.conf /run/dhcpcd/ntp.conf.br0.ra 952 rm -f /run/dhcpcd/ntp.conf.br0.ra ...

Here is another example where we trace the executions by make into a file, with the -t flag extrace(1) adds the exit status and the duration.