天涼好個秋.

windows进程休眠

1651 阅 0 评 问题&解决方案

去年换了入门版的 Surface Book,买了 TF 卡和 Dock,存储容量和接口也都够用,软件上,配合 WSL 能很好的完成日常的工作。作为二合一设备,工作之余随时变成平板电脑,看看新闻听听歌还是很棒的,但尴尬之处在于,之前打开的桌面应用,比如:Chrome 、微信、QQ、IDE 会让平板模式下设备发烫,但还不好关掉,因为休息事件过了还要重新打开。所以才有了接下来的对策。

对策

如果关掉程序麻烦,那干脆想办法 暂停进程?

Google 了下,找到了 pssuspend 程序

C:\Users\MarIxs>pssuspend /h

PsSuspend v1.07 - Process Suspender
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals

PsSuspend suspends or resumes processes on a local or remote NT system.

Usage: pssuspend [-r] [\\RemoteComputer [-u Username [-p Password]]] <process Id or name>
     -r    Resume.
     -u    Specifies optional user name for login to
           remote computer.
     -p    Specifies optional password for user name. If you omit this
           you will be prompted to enter a hidden password.
     -nobanner Do not display the startup banner and copyright message.

试用下

C:\Users\MarIxs>pssuspend qq.exe

PsSuspend v1.07 - Process Suspender
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals

Process qq.exe suspended.

QQ确实被暂停了,接下来用 -r 参数恢复。

C:\Users\MarIxs>pssuspend qq.exe -r

PsSuspend v1.07 - Process Suspender
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals

Process qq.exe resumed.

进程被暂停后,cpu 占用会变成 0 ,内存占用并没有被释放(这也是应该的),而且程序本身会变得无响应。

另一个问题是 pssuspend 每次只能暂停一个进程,感觉效率略低。

再寻找

这次不止 Google、还搜了下 GitHub,果然有收获
https://github.com/craftwar/suspend

Usage:

suspend.exe [-n] [-r] [-s] ProcessName1 [ProcessName2] .....

Options
switch can be specified in any postion (first ones are recommended)
-n  no operation mode (for test or whatever)
-r  resume mode
-s  case sensitive (case insensitive if not specified)

ex:
to suspend
suspend.exe a.exe b.exe

to resume
suspend.exe -r a.exe b.exe

测试下

C:\Users\MarIxs>suspend qq.exe chrome.exe
suspended process(es):
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
QQ.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe

看样很给力,恢复试试

C:\Users\MarIxs>suspend qq.exe chrome.exe -r
resumed process(es):
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
QQ.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe
chrome.exe

很不错

边边角角

一个进程在暂停时是全屏的,那么暂停后,就再也没办法把它最小化了,所以还需要在暂停前把窗口最小化,为了完成这个操作,我又找到了另一个工具 NirCmd http://nircmd.nirsoft.net
使用 sendkey 发送 win + m 将所有窗口最小化,之后再暂停进程,完美~

成品

配合 Listary

最后

好久没像这样折腾了..

EOF