Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bulpros.javaknights.social;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class ProcessInformation {
- public static void main(String[] args) throws IOException {
- List<ProcessInfo> processMyInfo = getProcesses(100000);
- }
- public static List<ProcessInfo> getProcesses(int memory) throws IOException {
- List<ProcessInfo> myResult = new ArrayList<>();
- try {
- String line;
- Process prc = Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
- BufferedReader input = new BufferedReader(new InputStreamReader(prc.getInputStream()));
- int counter = 0;
- while ((line = input.readLine()) != null) {
- counter++;
- if(counter > 3) {
- String processName = line.split("[ ]{2,}")[0];
- Pattern pattern = Pattern.compile("�| [K]");
- Matcher matcher = pattern.matcher((line.split("[ ]{2,}")[3]));
- int processMemory = Integer.parseInt(matcher.replaceAll(""));
- if(processMemory > memory) {
- ProcessInfo processInfo = new ProcessInfo(processName, processMemory);
- myResult.add(processInfo);
- processInfo.printAsString();
- }
- }
- }
- input.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return myResult;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement