I am running a java program and want to get the cpu that the process is currently running on. Is there any standard way in java to get this?
My backup plan is to run something like ps -eF
to get the cpu for my current process but that seems ugly
Data that you are looking for is not a static data but dynamic one and in my opinion should ideally be part of Java java.lang.Thread
class where a method call similar to this Thread.currentThread().getCPUNumber()
should give you that detail.
Java should shield OS specific system calls and provide that data at API level.
As far as I know, the answer is NO for your question - Is there any standard way in java to get this? because this data being dynamic and OS being thread scheduler, it couldn't be part of System.getProperty(...)
OR System.getenv(..)
OR Runtime.getRuntime().
.
I guess, as suggested in these SO questions , you have to make OS specific system calls from within your Java Thread - Q1 , Q2 .
Hope it helps !!