strace on Mac OS X Leopard
One of the most important tools for sysadmins and programmers working in the Linux/BSD environment is called strace. As it took me some time to find out where is “strace for Mac”, I thought it would be worth documenting here…
Making a long story short: in Tiger it was called
ktrace, in Leopard it’s called
dtrace, but it’s simpler if you just call
Here are some examples directly from the dtruss man page:
dtruss df -h # run and examine the "df -h" command dtruss -p 1871 # examine PID 1871 dtruss -n tar # examine all processes called "tar"
For a more “real-life” example, please see this article: Why DTrace Makes Leopard a Must-Have Upgrade — you’ll even learn how to prevent Time Machine from consuming all your CPU.
UPDATE: Just after posting this I discovered that:
1. There’s a really cool GUI for DTrace called Instruments. After playing with it for just a few minutes I was able to detect that it was psyco that was causing Python 2.4 to segfault when running web2ldap. Now back to a little more tinkering to discover why…
2. Leopard/DTrace provides one command that I always wanted: iotop, to show which processes are responsible for the disk I/O (more dtrace commands here). Now to the question: is there a Linux version? The answer is: yes, and it’s written in Python (and requires a kernel >= 2.6.20).