publicstaticvoid main(String[] args) throws Throwable { if (! new File("/usr/bin/perl").canExecute() ||
! new File("/bin/ps").canExecute()) return;
System.out.println("Looks like a Unix system."); long mypid = ProcessHandle.current().pid();
System.out.printf("mypid: %d%n", mypid);
final Runtime rt = Runtime.getRuntime();
try {
String[] cmd = {"no-such-file"};
rt.exec(cmd); thrownew Error("expected IOException not thrown");
} catch (IOException expected) {/* OK */}
try {
String[] cmd = {"."};
rt.exec(cmd); thrownew Error("expected IOException not thrown");
} catch (IOException expected) {/* OK */}
try {
String[] cmd = {TrueCommand};
rt.exec(cmd, null, new File("no-such-dir")); thrownew Error("expected IOException not thrown");
} catch (IOException expected) {/* OK */}
Process p = rt.exec(TrueCommand);
ProcessHandle pp = p.toHandle().parent().orElse(null);
System.out.printf("%s pid: %d, parent: %s%n", TrueCommand, p.pid(), pp);
p.waitFor();
// Count all the zombies that are children of this Java process final String[] zombieCounter = { "/usr/bin/perl", "-e", "$a=`/bin/ps -eo ppid,pid,s,command`;" + "print @b=$a=~/^ *@{[getppid]} +[0-9]+ +Z.*$/mog;" + "exit @b"
};
ProcessBuilder pb = new ProcessBuilder(zombieCounter);
pb.inheritIO(); int zombies = pb.start().waitFor(); if (zombies != 0) { thrownew Error(zombies + " zombies!");
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.41 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.