简体   繁体   English

如何使用Java在Unix / Linux中获取运行过程详细信息

[英]How to get running process details in Unix/Linux with java

I'm trying to get all current processes in Ubuntu with Java. 我正在尝试使用Java在Ubuntu中获取所有当前进程。 I really have no idea how to get them. 我真的不知道如何得到他们。 Please help me through this. 请帮助我。 Thanks in advance! 提前致谢!

Java is cross platform, Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running Java是跨平台的,每个Java应用程序都有一个Runtime类的实例,该实例允许该应用程序与运行该应用程序的环境进行交互

So in order to get the running processes use this: 因此,为了获得正在运行的进程,请使用以下命令:

String processStr;
Process p = Runtime.getRuntime().exec("ps -few");
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((processStr = input.readLine()) != null) {
            System.out.println(processStr); 
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM