digitalmars.D.learn - Processes
- Tomas (3/3) Jan 13 2013 Hey, guys.
- 1100110 (22/25) Jan 13 2013 ---
- maarten van damme (5/32) Jan 13 2013 You can use the win32 bindings to get a list of all running processes.
- David (1/24) Jan 15 2013 If you're already using `shell`: shell("killall %s".format(process));
- Nick Sabalausky (4/8) Jan 15 2013 Sounds like a fantastic tool! I'd love to see it when it's done! I
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.)
Jan 13 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.
Jan 13 2013
You can use the win32 bindings to get a list of all running processes. To kill one, follow : http://stackoverflow.com/questions/10807553/stop-external-program-from-c-code And instead of "system" use "shell" 2013/1/14 1100110 <0b1100110 gmail.com>: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.
Jan 13 2013
--- 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. } } ---If you're already using `shell`: shell("killall %s".format(process));
Jan 15 2013
On Sun, 13 Jan 2013 15:01:30 +0100 "Tomas" <Butkustomas777 gmail.com> 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.)Sounds like a fantastic tool! I'd love to see it when it's done! I might actually start using the PC version of Skype :)
Jan 15 2013