PlatoManiac
PlatoManiac

Reputation: 1442

Shutting down a windows process from Mathematica

One can see there are list of process running in a Windows operating system just by opening the task manager. Now my question is if it is possible to shut down one such process from Mathematica front end.

enter image description here

I mean we need to write a script say to kill the "Process Tree" if the process is taking more than 95 percent of system RAM or it takes more than X minutes or seconds to complete. I dont know if that can be done from MMA but if possible it will come really handy in my project.

BR

Upvotes: 2

Views: 220

Answers (2)

Chris Degnen
Chris Degnen

Reputation: 8645

I used a method to shut down a process in my reply here:

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

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

E.g. shutting down notepad:

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

This can be used in conjunction with tasklist to identify memory use:

ReadList["!tasklist", String]

Upvotes: 2

Mr.Wizard
Mr.Wizard

Reputation: 24336

You will probably want to use the Run function, and the TSKILL shell command.

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.

Upvotes: 2

Related Questions