Solved

Processes

Posted on 2004-09-23
4
214 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
  • 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now