pCloud Partner Program

快速kill process的方式(Windows)

系統技術/Windows 2008/10/18 11:10
views: 151216 times
手邊剛好在處理一個大量 process 未結束於系統上的一個問題. 該 server 不知什麼原因, 在起動 cgi 程式時, 發生了這個現象, 偶發的不會自行結束, 於是在系統內就留下了許多該 process 的名稱. 利用 task manager 會看到大量的 process, 雖未佔用 cpu, 不過會吃掉一部分的記憶.

在不方便重開 server 的狀況下, 如何快速地將相同名稱的 process 一起刪除呢? 於是上網想查看看有沒有什麼方便的小工具可以做這件事. 結果很順利地找到系統內建的一個指令: taskkill

這個指令是給定要刪除的 pid 或 image name (就是執行檔名稱), 來進行 process kill 的動作. 簡單研究一下, 進行了測試, 效果相當不錯, 800多個 process 一下就刪完了, 使用的指令如下:

taskkill /IM mytest.exe /F

如此一來, 所有 mytest.exe 的 process 一口氣就被 kill 完成了.

另外有許多方便的參數可供使用, 詳情可以利用 taskkill /? 來取得說明, 列表如下:

TASKKILL [/S system [/U username [/P [password]]]]
         { [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]

    This tool is used to terminate tasks by process id (PID) or image name.

Parameter List:
    /S    system           Specifies the remote system to connect to.

    /U    [domain\]user    Specifies the user context under which the
                           command should execute.

    /P    [password]       Specifies the password for the given user
                           context. Prompts for input if omitted.

    /FI   filter           Applies a filter to select a set of tasks.
                           Allows "*" to be used. ex. imagename eq acme*

    /PID  processid        Specifies the PID of the process to be terminated.
                           Use TaskList to get the PID.

    /IM   imagename        Specifies the image name of the process
                           to be terminated. Wildcard '*' can be used
                           to specify all tasks or image names.

    /T                     Terminates the specified process and any
                           child processes which were started by it.

    /F                     Specifies to forcefully terminate the process(es).

    /?                     Displays this help message.

    Filter Name   Valid Operators           Valid Value(s)
    -----------   ---------------           -------------------------
    STATUS        eq, ne                    RUNNING |
                                            NOT RESPONDING | UNKNOWN
    IMAGENAME     eq, ne                    Image name
    PID           eq, ne, gt, lt, ge, le    PID value
    SESSION       eq, ne, gt, lt, ge, le    Session number.
    CPUTIME       eq, ne, gt, lt, ge, le    CPU time in the format
                                            of hh:mm:ss.
                                            hh - hours,
                                            mm - minutes, ss - seconds
    MEMUSAGE      eq, ne, gt, lt, ge, le    Memory usage in KB
    USERNAME      eq, ne                    User name in [domain\]user
    MODULES       eq, ne                    DLL name
    SERVICES      eq, ne                    Service name
    WINDOWTITLE   eq, ne                    Window title

    1) Wildcard '*' for /IM switch is accepted only when a filter is applied.
    2) Termination of remote processes will always be done forcefully (/F).
    3) "WINDOWTITLE" and "STATUS" filters are not considered when a remote
       machine is specified.

    TASKKILL /IM notepad.exe
    TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
    TASKKILL /F /IM cmd.exe /T
    TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
    TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
    TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"


參考資料: XP: kill a Windows process from the command line with taskkill


Trackback Address :: http://diary.tw/tim/trackback/589

  1. Tracked from specialized building construction 2018/01/07 19:34 DELETE

    Subject: specialized building construction

    Click here for top quality design builder currently available in addition on sale today!
  2. Tracked from where to buy quartz clock movements 2018/01/11 19:16 DELETE

    Subject: where to buy quartz clock movements

    See the best available clock part that's now in stock and at the best price but you must get it today!
  3. Tracked from clock dials 2018/01/12 03:08 DELETE

    Subject: clock dials

    Get the best option for clock kit manufacturer currently now in stock and at the best price but you must get it today!
  1. 2008/10/21 02:11 MODIFY/DELETE REPLY


Write a comment

PREV : [1] : ... [311] : [312] : [313] : [314] : [315] : [316] : [317] : [318] : [319] : ... [475] : NEXT

Nextbit Robin 5.2吋六核心智慧型手機 Microsoft Office 365 中文家用版PKC (無光碟)
ASUS華碩 AC1900 雙頻無線路由器 RT-AC68U 美國 VORNADO 533 渦流空氣循環機 (黑色)
御茶園 每朝健康綠茶(650mlx24入) 每朝健康 雙纖綠茶(650mlx24入)