• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting list of Operating System prosesses into Java Application

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get all the currently executing processes into my java process. ( You can view those processes list if you go into task manager & selecing processes). But I need these list to be accessed from my java application . How can i do so...
 
Sheriff
Posts: 22785
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Shailesh S.",

Please read your private messages regarding an important announcement.

Thank you,

Rob



Now about your problem. There are two ways:
1) use JNI; you will need native Windows functions CreateToolhelp32Snapshot, Process32First, Process32Next and CloseHandle, plus native structure ProcessEntry.

2) execute tasklist.exe (located in C:\WINDOWS\system32) using ProcessBuilder / Runtime.exec and parse the results. Check out "tasklist /?" for more options. Especially the "/FO CSV" can be useful to make it a bit easier to parse.
 
Shailesh Sukare
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried second way. It worked correctly. But this is a solution for Windows platform. Now if I want list of Processes on Linux/Unix platform in that is there any way?
 
Rob Spoor
Sheriff
Posts: 22785
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Execute "ps" instead of tasklist.exe. "ps --help" or "man ps" can help you out.

Unfortunately, there is no platform independent way to do this.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.getProperty("os.name") will tell you which OS your're dealing with, so you can implement both ways and the choose the appropriate one at runtime.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic