How to pause / resume any external process under Windows?

*爱你&永不变心* 提交于 2019-11-29 04:21:54

If you "debug the debugger" (for instance, using logger.exe to trace all API calls made by windbg.exe), it appears that the debugger uses SuspendThread()/ResumeThread() to suspend all of the threads in the process being debugged.

PsSuspend may use a different way of suspending processes (I'm not sure), but it is still possible to hang other processes: if the process you're suspending is holding a shared synchronization object that is needed by another process, you may block that other process from making any progress. If both programs are well-written, they should recover when you resume the one that you suspended, but not all programs are well-written. And if this causes your program that is doing the suspending to hang, then you have a deadlock.

Highmastdon

I'm not sure if this does the job, but with ProcessExplorer from MS Systernals you can suspend a process.

It's been said here: https://superuser.com/a/155263 and I found it there too.

Hanan N.

read here and you also have psutil for python that you can use it like that:

>>> import psutil
>>> pid = 7012
>>> p = psutil.Process(pid)
>>> p.suspend()
>>> p.resume()

I tested http://www.codeproject.com/KB/threads/pausep.aspx on few softwares:

it works fine.

PsSuspend and Pausep are two valid options.

I think there is a good reason why there is no SuspendProcess() function in Windows. Having such a function opens the door for an unstable system. You shall not suspend a process unless you created that process yourself. If you wrote that process yourself, you could use an event (see ::SetEvent() etc. in MSDN) or another kind of messaging to trigger a pause command in the process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!