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.
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.
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.
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
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