Java program acquires process information of linux server

searched for a lot of information about getting Linux, but found no detailed description of the process information for getting linux server.

Let"s solve here. Is it possible to read the process information from the native linux server where the code is executed in the java code?
this question is divided into three small questions:
1: can you specify that only the process information under a certain user can be obtained?
2: can I get information about the specified process?
3: can I get multi-dimensional information under commands such as ps-ef and ps aux?

my idea now is to use Runtime.getRuntime (). Exec () to call shell to get information, but I want to get this information without using shell, just like you can get IP information directly by calling java.net.InetAddress. Can there be such an encapsulated package implementation?
ask for advice! Thank you!

Mar.15,2021

since exec, wants ps-ef, again, why not exec ("ps-ef")

public static void main(String[] args) throws Exception {

     try {
       String line;
       Process p = Runtime.getRuntime().exec( "ps -ef" );

       BufferedReader in = new BufferedReader(
               new InputStreamReader(p.getInputStream()) );
       while ((line = in.readLine()) != null) {
         System.out.println(line);
       }
       in.close();
     }
     catch (Exception e) {
       // ...
     }
}

https://github.com/oshi/oshi
github has an open source project that can obtain hard disk and CPU information. You can try

.
Menu