2011-12-07 25 views
2

只需打開任務管理器,就可以看到在Windows操作系統中運行的進程列表。現在我的問題是,是否有可能從Mathematica前端關閉一個這樣的進程。關閉Mathematica中的Windows進程

enter image description here

我的意思是,我們需要編寫一個腳本說殺「進程樹」如果進程正在系統內存的95%以上或時間超過X幾分鐘或幾秒鐘即可完成。我不知道這是否可以從MMA完成,但如果可能的話,它會在我的項目中非常方便。

BR

回答

2

我使用的方法在我的答覆這裏關閉進程:

How can I make Mathematica kernel pause for an external file creation

taskkill /f /fi "imagename eq apame_win64.exe" 

例如關閉記事本:

ReadList["!taskkill /F /FI \"IMAGENAME eq notepad.exe\"", String] 

這可以在任務列表一起使用,以確定內存使用:

ReadList["!tasklist", String] 
2

你可能會想使用Run功能,並且TSKILL shell命令。

TSKILL processid | processname [/SERVER:servername] [/ID:sessionid | /A] [/V] 

    processid   Process ID for the process to be terminated. 
    processname   Process name to be terminated. 
    /SERVER:servername Server containing processID (default is current). 
         /ID or /A must be specified when using processname 
         and /SERVER 
    /ID:sessionid  End process running under the specified session. 
    /A     End process running under ALL sessions. 
    /V     Display information about actions being performed. 
+0

你能不能給我一個簡單的例子? – PlatoManiac

+0

@Plato,對不起,我認爲那部分很明顯。如果'notepad.exe'正在運行,只需運行[「TSKILL記事本」]'。 –