2
import java.io.IOException;
import org.hyperic.sigar.*;
public class SigarDemo {
public static void main(String args[]) throws SigarException, IOException
{
final Sigar sigar = new Sigar();
final long[] processes = sigar.getProcList();
ProcTime pt=new ProcTime();
for (final long processId : processes) {
ProcUtil.getDescription(sigar, processId);
pt=sigar.getProcTime(processId);
System.out.println("---"+pt.getStartTime());
}
}
我正在嘗試使用sigar獲取每個進程的進程時間。我得到這個錯誤:使用sigar無法獲取進程時間
Exception in thread "main" java.lang.ExceptionInInitializerError at taskmanager.SigarDemo.main(SigarDemo.java:22) Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "sigar.nativeLogging" "read") at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457) at java.security.AccessController.checkPermission(AccessController.java:884) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294) at java.lang.System.getProperty(System.java:714) at org.hyperic.sigar.Sigar.(Sigar.java:78)
我已經試過策略文件設置所有權限。但我仍然收到錯誤。我正在使用netbeans 8.0。我已經設定
-Djava.security.manager -Djava.security.policy=src/dir1/dir2/important.policy
感謝答覆..它是工作.. –
但我實際的問題是如何避免「SigarExceptionPermissionDenied」?我知道..我應該寫政策文件的許可。但如何寫它,並在哪裏發佈? –