package commands; import java.io.*; import java.util.List; import kernel.*; /** * Prints all running processes. * * @author Tomáš Podskalský */ public class ps extends AbstractProcess { public void realization() throws AppException { PipedOutputStream output = (this.getOut() != null) ? (PipedOutputStream) this .getOut() : null; List processes = getServices().getProcesses(); try { for (AbstractProcess process : processes) if (process.getID() != this.getID()) { String s = new String("[" + process.getID() + "] " + process.getCommand() + "\n"); output.write(s.getBytes()); output.flush(); } String s = new String("[" + this.getID() + "] " + this.getCommand() + "\n"); output.write(s.getBytes()); output.flush(); } catch (IOException ioe) { ioe.printStackTrace(); throw new AppException("Chyba I/O\n" + ioe.getMessage(), ioe); } catch (NullPointerException npe) { npe.printStackTrace(); throw new AppException("Output není definován\n" + npe.getMessage(), npe); } catch (Exception e) { e.printStackTrace(); throw new AppException("Neznámá Chyba.\n" + e.getMessage(), e); } } /** * Provides help for users. * */ public String getHelp() { return "\n\nDescription:\nPrints all running processes.\n\n"; } }