[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Processes

Posted on 2004-09-23
4
Medium Priority
?
223 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 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