aspose file tools
The moose likes Threads and Synchronization and the fly likes Get a list of Processes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Get a list of Processes " Watch "Get a list of Processes " New topic
Author

Get a list of Processes

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
I just wanted to know, is there a way to get a list of processes which are currently running in the Operating System.
Thanks...


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I doubt there is a platform-independent way to do such a thing.
In any case, I'm moving this to the Threads and Synchronization forum, where folks are most likely to have an idea...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
By the way, why would you want to do such a thing?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

There's no Java API for this. You have two choices: a platform-dependent JNI function that uses the native OS's mechanism for getting this list, or using Runtime.exec() to run some platform-dependent program that returns the list as text and then parsing the result.


[Jess in Action][AskingGoodQuestions]
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Could you please give me any idea if I want to do this by Runtime.exec()...
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
What operating system are you using?


"I'm not back." - Bill Harding, Twister
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
I am using Windows 2000 platform. I don't mind doing this machine dependantly as well as using JNI.
Please do help me with this. This is an assignment.
Thanks.........
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
You might look at this Win32 API fuction:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/enumprocesses.asp
then, follow the links for code examples, etc. And get more info on process-relevant part of Win32 API here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_and_thread_functions.asp
And you need to wrap this stuff in JNI, of course...
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
...and using pure Java you can track (to some degree) only the processes which your application have started by callimg Runtime.exec(...) If you need to track other processes, it will not work for you.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
Thank you very much for the answers. It really helps...........
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
I am facing a problem. The link above which was given to me, provided me a source code written on C or C++. Could you please tell me which software do I have to use to run the program.
Thanks....
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
C/C++ development tool like Microsoft Visual Studio (IMHO overkill for your task), or "gcc" http://gcc.gnu.org/
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Bloodshed's Dev C++ is pretty easy to use, and it's free.
If you've further questions on C/C++ development, let me suggest that you mosey on over to Gregg's forums dedicated to the subject.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Thank you very much for the answers......
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Get a list of Processes
 
Similar Threads
Getting list of Operating System prosesses into Java Application
Retrieving System Processes in Windows
Finding processe in Windows XP
Retrieve task manager processes - Win2000
computer has become very slow