?
Solved

Processes

Posted on 2004-09-23
4
Medium Priority
?
220 Views
Last Modified: 2010-04-15
Good morning, all,

In a console application, how would I go about listing all the processes currently running by pID, and then terminating a process by pID?  The more info the better, I am *Very* new at this!  Thanks in advance!

Regards,
Tony
0
Comment
Question by:fattumsdad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 12134834
To 'Kill' (Terminate) a Process by PID use:

  int pid = ...;
  System.Diagnostics.Process process = System.Diagnostics.Process.GetProcessById(pid);
  process.Kill();
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 2000 total points
ID: 12134864
To GET the processes you can use this:

  System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
  foreach(System.Diagnostics.Process process in processes)
  {
    string processName = process.ProcessName;
    int processId = process.Id;
  }
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12135372
eternal,

How do I actually display the processes in the console?  I put the above code (to get processes) and it compiles / runs fine...  but just gives me  a "press any key to continue".  I tried adding Console.WriteLine(processName, processID); to no avail.  Any suggestions? :)
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12135421
Nevermind!  Got it working!  Thanks for the help!
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question