3

I have the process id of a process. Can I get other information about process like CPU%, memory, exe name, etc?

I have seen that there is no built-in function to get all this. How to do this with Native?

Please help.

Ravi Kumar Gupta
  • 1,698
  • 2
  • 22
  • 38

3 Answers3

2

Java is a platform independent platform. Its specification doesn't define anything about pid. So you cannot find a general/portable way to manipulate pid. Although it is not a good practice, you can make an implemenation for a specific platform.

On windows you can use tasklist to get the full list of PIDs and filter for the one you want.

On Unix/Linux system you can use ps ax | grep to get your information.

StarPinkER
  • 14,081
  • 7
  • 55
  • 81
1

Well, all of those information you can get from the OS. For example, the task manager in Windows.

What Java can offer you is, for example, the thread dump:

%JAVA_HOME%/bin/jstack.exe PID >stack.txt

Or, the heap dump:

%JAVA_HOME%/bin/jmap.exe -dump:format=b,file=heap.bin PID
darijan
  • 9,725
  • 25
  • 38
0

In-built to java there is no API exposed for this to my knowledge:

But you can couple java with OS native command to fetch the info.

e.g.

Windows explore (tasklist): http://msdn.microsoft.com/en-us/library/windows/hardware/ff545415(v=vs.85).aspx

Unix explore (ps): Shell script to get the process ID on Linux

Community
  • 1
  • 1
Himanshu Bhardwaj
  • 4,038
  • 3
  • 17
  • 36