Để tìm số pid
(cần tìm thông tin về một quy trình nhất định), bạn có thể sử dụng ProcessFinder
. Phương pháp tìm pid xử lý đơn là findSingleProcess(String expression)
. Ví dụ:
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()));
Cú pháp biểu hiện là:
Class.Attribute.operator=value
đâu:
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
Thông tin thêm ở đây: http://support.hyperic.com/display/SIGAR/PTQL
tôi đã sử dụng SIGAR trước đó, và thấy nó khá dễ dàng. Bạn có thể chỉ định chính xác những gì bạn đang tìm kiếm không? Trang tài liệu PTQL kết hợp với javadoc có vẻ là một khởi đầu khá tốt với tôi. –
Vì vậy, như là một điểm khởi đầu, tôi cần thông tin về việc sử dụng bộ nhớ/bộ nhớ cho một quá trình nhất định, như explorer.exe (ví dụ). – CosminO
Đây là một chút đoán, vì vậy tôi sẽ không đăng bài trả lời này; Tôi nghĩ bạn chỉ làm ProcMem pm = new ProcMem(); pm.gather (sigar, yourPid); pm.getsize(). Tương tự cho cpu với ProcTime. Bạn có thể sử dụng ProcessFinder để tìm một pid từ một biểu thức PTQL. –