How can I redirect OS X dtruss output when running with sudo?

9

3

I'm running dtruss on Mac OS X 10.9. Simple example is:

sudo -c ls

But I'd like to capture the dtruss output into a file. I saw something that suggests that I can do something like:

sudo bash -c 'dtruss -c ls >x'

but when I do this the output of dtruss still goes to the terminal and the list of file from ls gets redirected to the file.

How can I redirect the output of dtruss to a file?

Chris Markle

Posted 2014-07-08T14:35:03.250

Reputation: 191

1

dtruss probably writes to stderr instead of stdout witch is what >x captures. This questions explains what to do: Linux less behavior and stderr

– Nifle – 2014-07-08T15:05:47.690

Answers

9

I've been running it like this:

sudo dtruss -f -p 12345 2> /tmp/trace.txt
  • -f says to follow child processes.
  • -p specifies which process ID to trace.
  • 12345 is a placeholder for a process ID. You could get that by looking at top or ps -A.
  • 2> pipes standard error into the output file. For some reason dtruss outputs everything on stderr.

Luke Quinane

Posted 2014-07-08T14:35:03.250

Reputation: 397

Could you expand your answer to explain what this does? Thanks. – fixer1234 – 2015-03-06T04:47:20.437

'-f' says follow child processes, '-p' specifies which process ID to trace, '2>' pipes standard error into the output file. For some reason dtruss outputs everything on stderr. – Luke Quinane – 2015-03-06T05:17:15.753

Is 12345 a placeholder for the process ID (and where would that come from)? – fixer1234 – 2015-03-06T05:23:12.537

It is a placeholder for a process ID. You could get that by looking at top or ps -A. – Luke Quinane – 2015-03-06T06:50:31.590