use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListTest method testOnWindows_WMIC_DoNotIncludeSystemIdleProcess.
public void testOnWindows_WMIC_DoNotIncludeSystemIdleProcess() throws Exception {
List<ProcessInfo> infos = ProcessListUtil.parseWMICOutput("Caption CommandLine ExecutablePath ProcessId \n" + "System Idle Process 0 \n" + "System 4 \n" + "smss.exe 304 \n");
assertOrderedEquals(infos, new ProcessInfo(4, "System", "System", ""), new ProcessInfo(304, "smss.exe", "smss.exe", ""));
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListTest method testMac_VariousFormsPidStatUser.
public void testMac_VariousFormsPidStatUser() throws Exception {
List<ProcessInfo> infos = ProcessListUtil.parseMacOutput(" PID STAT USER COMMAND\n\n" + " 1 S user /dir/file\n" + " 101 Ss user_name /dir/file\n", " PID STAT USER COMM\n\n" + " 1 S user /dir/file\n" + " 101 Ss user_name /dir/file\n");
assertOrderedEquals(infos, new ProcessInfo(1, "/dir/file", "file", "", "/dir/file"), new ProcessInfo(101, "/dir/file", "file", "", "/dir/file"));
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListTest method testMac_DoNotIncludeProcessedMissingOnTheSecondPSRun.
public void testMac_DoNotIncludeProcessedMissingOnTheSecondPSRun() throws Exception {
List<ProcessInfo> infos = ProcessListUtil.parseMacOutput(" PID STAT USER COMM\n\n" + " 1 S user /dir/file\n" + " 2 S user /dir/file\n", " PID STAT USER COMMAND\n\n" + " 1 S user /dir/file\n" + " 5 S user /dir/file\n");
assertOrderedEquals(infos, new ProcessInfo(1, "/dir/file", "file", "", "/dir/file"));
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListUtil method getProcessListOnUnix.
@Nullable
private static List<ProcessInfo> getProcessListOnUnix() {
File proc = new File("/proc");
File[] processes = proc.listFiles();
if (processes == null) {
LOG.error("Cannot read /proc, not mounted?");
return null;
}
List<ProcessInfo> result = new ArrayList<>();
for (File each : processes) {
int pid = StringUtil.parseInt(each.getName(), -1);
if (pid == -1)
continue;
List<String> cmdline;
try {
FileInputStream stream = new FileInputStream(new File(each, "cmdline"));
try {
//noinspection SSBasedInspection - no better candidate for system encoding anyways
String cmdlineString = new String(FileUtil.loadBytes(stream));
cmdline = StringUtil.split(cmdlineString, "\0");
} finally {
stream.close();
}
} catch (IOException e) {
continue;
}
if (cmdline.isEmpty())
continue;
String executablePath = null;
try {
File exe = new File(each, "exe");
if (!exe.getAbsolutePath().equals(exe.getCanonicalPath())) {
executablePath = exe.getCanonicalPath();
}
} catch (IOException e) {
// couldn't resolve symlink
}
result.add(new ProcessInfo(pid, StringUtil.join(cmdline, " "), PathUtil.getFileName(cmdline.get(0)), StringUtil.join(cmdline.subList(1, cmdline.size()), " "), executablePath));
}
return result;
}
use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.
the class ProcessListUtil method parseWMICOutput.
@Nullable
static List<ProcessInfo> parseWMICOutput(@NotNull String output) {
List<ProcessInfo> result = ContainerUtil.newArrayList();
String[] lines = StringUtil.splitByLinesDontTrim(output);
if (lines.length == 0)
return null;
String header = lines[0];
int commandLineStart = header.indexOf("CommandLine");
if (commandLineStart == -1)
return null;
int pidStart = header.indexOf("ProcessId");
if (pidStart == -1)
return null;
int executablePathStart = header.indexOf("ExecutablePath");
if (executablePathStart == -1)
return null;
for (int i = 1; i < lines.length; i++) {
String line = lines[i];
int pid = StringUtil.parseInt(line.substring(pidStart, line.length()).trim(), -1);
if (pid == -1 || pid == 0)
continue;
String executablePath = line.substring(executablePathStart, pidStart).trim();
String name = line.substring(0, commandLineStart).trim();
if (name.isEmpty())
continue;
String commandLine = line.substring(commandLineStart, executablePathStart).trim();
String args = "";
if (commandLine.isEmpty()) {
commandLine = name;
} else {
args = extractCommandLineArgs(commandLine, name);
}
result.add(new ProcessInfo(pid, commandLine, name, args, executablePath));
}
return result;
}
Aggregations