/* * kill.java * * Implementation of the KILL command. */ package commands; import kernel.*; /** * Terminates one or more processes according to the given PIDs. * * @author Jan Horky */ public class kill extends AbstractProcess { /** * Realizes the KILL command. * * @throws AppException * Exception caused by an error in the virtual machines manager. */ public void realization() throws AppException { if (getArgs().size() == 0) this.printError("kill: Too few arguments\n"); else for (String arg : getArgs()) { int pid = -1; AbstractProcess process = null; try { pid = Integer.parseInt(arg); process = getServices().getProcess(pid); process.kill(); } catch (NumberFormatException nfe) { this.printError("kill: Invalid argument " + pid + "\n"); } catch (NullPointerException npe) { this.printError("kill: Process " + pid + " doesn't exist\n"); } } } /** * Provides full description of the command to be used in the MAN command. * * @return Full description of the command including the syntax. */ public String getHelp() { return "\n\nDescription:\nTerminates selected processes according to the given PIDs.\n\nUsage:\n" + "kill [PID1 [PID2 [...]]]\n\n" + "PID1, PID2, ...\tIDs of the processes to be terminated"; } }