Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing and terminating processes in .Net

Tags:

c#

.net

How can I list and terminate existing processes in .Net application? Target applications are 1) .Net applications, 2) they are instances of the same executable 3) they have unique Ids but I don't know how to get this information from them, 4) they are spawned externally (i.e. I do not have handles to them as I don't create them).

I want to list all processes, get unique ids from them and restart some of them. I assume that all of them are responsive.

like image 276
Karol Kolenda Avatar asked Feb 02 '26 12:02

Karol Kolenda


2 Answers

You can grab a list of running processes with Process.GetProcesses static method. You can easily query the return value (possibly with LINQ) to get the ones you want.

System.Diagnostics.Process.GetProcesses()
like image 130
mmx Avatar answered Feb 04 '26 02:02

mmx


Process.Kill();

Check this out for killing processes: http://www.dreamincode.net/code/snippet1543.htm

The Process Id is a property of the process. Eg:

Process.Id

All of the methods available on the process are listed here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process_methods.aspx

like image 22
grenade Avatar answered Feb 04 '26 01:02

grenade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!