Here’s a one minute read, about a trick which I discovered today:
When running an strace, it’s common to do something like:
Smarter hackers know that they can use some bash magic and do:
strace -p`pidof <process name>`
However, if you’re tracing a script named foo.py, this won’t work because the real process is the script’s interpreter, and pidof python, might return other unrelated python scripts.
strace -p`pidof foo.py` # won't work [failure] [user sifting through ps output for real pid] [computer explodes]
The trick is to use the -x flag of pidof. This will let you pass in your script’s name, and pidof will take care of the rest:
strace -p`pidof -x foo.py` # works! [user cheering] [normal strace noise]