Processes
1100110
0b1100110 at gmail.com
Sun Jan 13 20:26:02 PST 2013
On 01/13/2013 08:01 AM, Tomas wrote:
> Hey, guys.
>
> I need to get all running processes list, and kill one. (example: Find
> all processes and if skype.exe is running, kill it.)
---
import std.stdio;
import std.process;
//assuming we want to kill "htop"
void main() {
killProcess("htop");
}
void killProcess(string n){
version(linux) {
auto processNumber = shell("pgrep "~ n);
writeln(n ~" process number is: "~processNumber);
shell("kill "~ processNumber);
writeln(n ~" has been killed.");
}
version(Windows) {// I don't know windows enough, your turn.
}
}
---
I assume it would be similar on Windows, since you will need to go
through the OS in any case, but this is a simple, hastily written
example since no one else has answered.
More information about the Digitalmars-d-learn
mailing list