Example #1
0
  public void testCreate() throws Exception {
    Sigar sigar = getSigar();

    try {
      sigar.getProcEnv(getInvalidPid());
    } catch (SigarException e) {
    }

    long pid = sigar.getPid();

    try {
      Map env = sigar.getProcEnv(pid);
      traceln(env.toString());

      String key = "JAVA_HOME";
      String val = (String) env.get(key);

      String single = sigar.getProcEnv(pid, key);

      if (val != null) {
        assertTrue(new File(val, "bin").exists());
        assertTrue(val.equals(single));
        traceln(key + "==>" + single);
      }

      key = "dOeSnOtExIsT";
      val = (String) env.get(key);
      assertTrue(val == null);

      val = sigar.getProcEnv(pid, key);
      assertTrue(val == null);
    } catch (SigarNotImplementedException e) {
      // ok
    } catch (SigarPermissionDeniedException e) {
      // ok
    }

    long[] pids = sigar.getProcList();

    for (int i = 0; i < pids.length; i++) {
      // traceln("pid=" + pids[i]);
      try {
        sigar.getProcEnv(pids[i]);
      } catch (SigarException e) {
      }
    }
  }
Example #2
0
  @Override
  public String getValue() throws Exception {
    Sigar sigar = new Sigar();
    long value = 0;
    long[] pids = sigar.getProcList();

    for (long pid : pids) {
      ProcState state = null;

      try {
        state = sigar.getProcState(pid);
      } catch (Exception e) {
        // Process exited!
      }

      if (state != null) {
        if (getProc().equals("ALL") || state.getName().equals(getProc())) {
          value += requestValue(sigar, value, pid, state);
        }
      }
    }

    return "" + value;
  }