This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to get process related information as shown in Task Manager in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get process related information as shown in Task Manager in java" Watch "How to get process related information as shown in Task Manager in java" New topic
Author

How to get process related information as shown in Task Manager in java

Bob Edward
Greenhorn

Joined: Nov 26, 2009
Posts: 2
Hi,

I want to get process related information as seen in Task Manager for windows. When process name is passed to my API, it should return a map consisting of following keys and values which will be dynamic according to process name. Example when I pass OUTLOOK.EXE to my API then it should return.

ImageName: Outlook.exe
PID: 1234
Username: xyz
CPU: 03%
Mem Usage: 22532K
Handles: 2141
Threads: 12

I was able to retrive the information upto Mem Usage through Runtime.exec("tasklist") and then parsing the output. Can some one guide me to retrive information for handles and threads. I will prefer not to use JNI.


Thanks
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Tasklist supports flags. Type tasklist/? on your command prompt to view them.
You can run the command with the appropriate flags, parse the output and retrieve the required values.
e.g. On my system right now Outlook's PID is 3572.
If I use tasklist /FI "PID eq 3572" I get the details for outlook.exe
Notice the quotes in the above command.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Bob Edward
Greenhorn

Joined: Nov 26, 2009
Posts: 2
Maneesh Godbole wrote:Tasklist supports flags. Type tasklist/? on your command prompt to view them.
You can run the command with the appropriate flags, parse the output and retrieve the required values.
e.g. On my system right now Outlook's PID is 3572.
If I use tasklist /FI "PID eq 3572" I get the details for outlook.exe
Notice the quotes in the above command.


This does not give any information regarding Handles and Threads. Need guidance how to get them.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
This article may help.

Bill
 
Don't get me started about those stupid light bulbs.
 
subject: How to get process related information as shown in Task Manager in java
 
Similar Threads
Memory Leak using System.arraycopy?
What could still be running after threads return?
WebServer's process management
java program problem
CPU usage and memory usage by processes