add ProcUtil.getDescription

This commit is contained in:
Doug MacEachern 2006-01-22 22:07:18 +00:00
parent a4ccf9a36b
commit 38e5a2ff35
2 changed files with 32 additions and 19 deletions

View File

@ -65,4 +65,35 @@ public class ProcUtil {
return null; return null;
} }
public static String getDescription(SigarProxy sigar, long pid)
throws SigarException {
String[] args;
ProcState state = sigar.getProcState(pid);
String name = state.getName();
try {
args = sigar.getProcArgs(pid);
} catch (SigarException e) {
args = new String[0];
}
if (name.equals("java") || name.equals("javaw")) {
String className = null;
try {
className = getJavaMainClass(sigar, pid);
} catch (SigarException e) {}
if (className != null) {
name += ":" + className;
}
}
else {
if (args.length != 0) {
name = args[0];
}
}
return name;
}
} }

View File

@ -120,25 +120,7 @@ public class Ps extends SigarCommandBase {
info.add(unknown); info.add(unknown);
} }
String name = state.getName(); String name = ProcUtil.getDescription(sigar, pid);
if (name.equals("java") || name.equals("javaw")) {
String className = null;
try {
className = ProcUtil.getJavaMainClass(sigar, pid);
} catch (SigarException e) {}
if (className != null) {
name += ":" + className;
}
}
else {
try {
String[] args = sigar.getProcArgs(pid);
if (args.length != 0) {
name = args[0];
}
} catch (SigarException e) {}
}
info.add(name); info.add(name);
return info; return info;