@Test public void getPidsObeysMaxPidsValue() throws IOException { Files.createDirectories(defaultProcRoot); Files.createDirectories(defaultPidMaxFilePath.getParent()); int pidMax = 15; Files.write(defaultPidMaxFilePath, (pidMax + "").getBytes()); createIncrementingPidsInRoot(defaultProcRoot, LinuxConstants.LOWEST_LEGAL_PID, pidMax + 25); List<Integer> pids = enumerator.getPids(); List<Integer> expected = IntStream.range(1, pidMax).mapToObj(i -> i).collect(Collectors.toList()); assertTrue(expected.containsAll(pids)); assertTrue(pids.containsAll(expected)); }
@Override public List<Integer> getPids() { int pidMax = readPidMax(); BiPredicate<Path, BasicFileAttributes> filter = new ProcPathFilter(pidMax); try { return Files.find(procRoot, 1, filter) .map(path -> Integer.parseUnsignedInt(path.getFileName().toString())) .collect(Collectors.toList()); } catch (IOException ex) { throw new ProcessEnumerationException("An error occurred while enumerating PIDs", ex); } }
LinuxPidEnumerator implements PidEnumerator { @Override public List<Integer> getPids() { int pidMax = readPidMax(); BiPredicate<Path, BasicFileAttributes> filter = new ProcPathFilter(pidMax); try { return Files.find(procRoot, 1, filter) .map(path -> Integer.parseUnsignedInt(path.getFileName().toString())) .collect(Collectors.toList()); } catch (IOException ex) { throw new ProcessEnumerationException("An error occurred while enumerating PIDs", ex); } } }
LinuxPidEnumerator implements PidEnumerator { @Override public List<Integer> getPids() { int pidMax = readPidMax(); BiPredicate<Path, BasicFileAttributes> filter = new ProcPathFilter(pidMax); try { return Files.find(procRoot, 1, filter) .map(path -> Integer.parseUnsignedInt(path.getFileName().toString())) .collect(Collectors.toList()); } catch (IOException ex) { throw new ProcessEnumerationException("An error occurred while enumerating PIDs", ex); } } LinuxPidEnumerator(Path procRoot, Path pathToPidMax); }
LinuxPidEnumerator implements PidEnumerator { @Override public List<Integer> getPids() { int pidMax = readPidMax(); BiPredicate<Path, BasicFileAttributes> filter = new ProcPathFilter(pidMax); try { return Files.find(procRoot, 1, filter) .map(path -> Integer.parseUnsignedInt(path.getFileName().toString())) .collect(Collectors.toList()); } catch (IOException ex) { throw new ProcessEnumerationException("An error occurred while enumerating PIDs", ex); } } LinuxPidEnumerator(Path procRoot, Path pathToPidMax); @Override List<Integer> getPids(); }
LinuxPidEnumerator implements PidEnumerator { @Override public List<Integer> getPids() { int pidMax = readPidMax(); BiPredicate<Path, BasicFileAttributes> filter = new ProcPathFilter(pidMax); try { return Files.find(procRoot, 1, filter) .map(path -> Integer.parseUnsignedInt(path.getFileName().toString())) .collect(Collectors.toList()); } catch (IOException ex) { throw new ProcessEnumerationException("An error occurred while enumerating PIDs", ex); } } LinuxPidEnumerator(Path procRoot, Path pathToPidMax); @Override List<Integer> getPids();  }