适用于JAVA的Sigar API(需要指南)

Cos*_*inO 5 java windows sigar

我已经下载了Sigar API(http://support.hyperic.com/display/SIGAR/Home),并希望在项目中使用它来获取有关正在运行的不同进程的信息.

我的问题是我无法找到一些有用的代码片段来学习,而且他们网站上的javadoc没有多大帮助,因为我不知道我应该寻找什么.

你有什么想法我可以找到更多信息吗?

Cos*_*inO 10

要找到pid(找到有关某个过程的信息所需的信息),您可以使用a ProcessFinder.找到单个进程pid的方法是findSingleProcess(String expression).例:

    Sigar sigar=new Sigar();
    ProcessFinder find=new ProcessFinder(sigar);
    long pid=find.findSingleProcess("Exe.Name.ct=explorer");
    ProcMem memory=new ProcMem();
    memory.gather(sigar, pid);
    System.out.println(Long.toString(memory.getSize()));
Run Code Online (Sandbox Code Playgroud)

表达式语法是这样的:

Class.Attribute.operator=value
Run Code Online (Sandbox Code Playgroud)

哪里:

Class is the name of the Sigar class minus the Proc prefix.
Attribute is an attribute of the given Class, index into an array or key in a Map class.
operator is one of the following for String values:
eq - Equal to value
ne - Not Equal to value
ew - Ends with value
sw - Starts with value
ct - Contains value (substring)
re - Regular expression value matches
operator is one of the following for numeric values:
eq - Equal to value
ne - Not Equal to value
gt - Greater than value
ge - Greater than or equal value
lt - Less than value
le - Less than or equal value
Run Code Online (Sandbox Code Playgroud)

更多信息请访问:http://support.hyperic.com/display/SIGAR/PTQL