This week’s Leansentry How-To article covers a tricky topic: how to recover from a failed CPU profiler that has frozen your process in production.
Recovering from a CPU profiling failure
This is something I hope you don’t have to do often, but it pays to know if you ever get into this situation. I have personally had to do this twice with the ANTs Profiler last year.
This also talks about different ways that you can profile in production, and the associated risks.
Temporarily freezing a process
I thought I would add another tip, which is the opposite of what the How-To is about: a dirty trick to freeze a process that you don’t want running (at least for a while), without killing it:
- Make sure you got your Windows Debuggers installed.
- Run this command:
ntsd -p PID -c "~*n;.detach;qq"
This will suspend all threads in the process, essentially “suspending” it until you give the go ahead. This DOES NOT leave the debugger attached to the process, and is different from “freezing” a thread which is only effective while the debugger is attached.
When ready, resume the process like this:
ntsd -p PID -c "~*m;.detach;qq"
I don’t recommend this trick unless you need it, because it can lead to possible issues including the process maintaining exclusive locks on files or mutexes, as well as failures when the process resumes and encounters network timeouts/unexpected time values.
However, it’s definitely still safer than killing the process if you don’t want it to run at the moment (e.g. usually does not corrupt data).
Hope you find this how-to useful, as always feel free to leave your feedback here. Until next week!