1 /**
2 * AUTOHIT 2003
3 * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Additional license information can be found in the documentation.
19 * @author Erich P Gatejen
20 */
21 package autohit.call;
22
23 import autohit.common.Constants;
24 import autohit.universe.Universe;
25 import autohit.vm.VM;
26 import autohit.vm.VMProcess;
27
28 /**
29 * CHECK_PROCESS call. It will see if a PID is still alive. It will return TRUE if it is, otherwise FALSE.
30 * <pre>
31 * REQURIES: logger, core
32 * IGNORES: uni
33 * PARAMETERS (INPUT):
34 * pid= PID for the process checked.
35 * </pre>
36 * RETURNS: It will return TRUE if it is, otherwise FALSE.
37 *
38 * @author Erich P. Gatejen
39 * @version 1.0
40 * <i>Version History</i>
41 * <code>EPG - Initial - 7APR05</code>
42 *
43 */
44 public class Call_CHECK_PROCESS extends Call {
45
46 // Trim the size of result logging in debug mode
47 final static private int TRIM_SIZE = 500;
48
49 /**
50 * Implement this to handle load time initialization. The
51 * four main fields will already be set--vmc, sc, log, and u.
52 * You must implement this, but you don't have to do anything.
53 * Remember that calls are cached per VM and reused as often
54 * as possible. There will be no thread-safety issues with the
55 * VMCore or log, but the SystemContecxt and Universe may be shared.
56 * @throws CallException
57 */
58 public void load_chain() throws CallException {
59 // Nothing to do.
60 }
61
62 /**
63 * Implement this to return the name of the CALL
64 * @return name of the CALL
65 */
66 public String name() {
67 return "CHECK_PROCESS";
68 }
69
70 /**
71 * Execute it.
72 * @return the result or null if there is no result
73 */
74 public String call() throws CallException {
75
76 String result = Constants.FALSE;
77 VM myVM;
78 String name = null;
79
80 try {
81
82 // see if the parameter is passed
83 name = this.requiredString("pid");
84 int pid = Integer.parseInt(name);
85
86 // Get the process and see if it is there
87 VMProcess pcb = sc.getKernel().getProcess(pid);
88 if (pcb == null) result = Constants.FALSE;
89 else if (pcb.getState() >= VM.STATE_ACTIVE_THRESHOLD) {
90 result = Constants.TRUE;
91 }
92
93 } catch (NumberFormatException ne) {
94 // Ignore this. This means the pid passed is bad. It will be reported as not found.
95
96 } catch (CallException e) {
97 throw e;
98
99 } catch (Exception ex) {
100 //any other is REAL bad
101 throw new CallException(
102 this.format("Serious fault. error=" + ex.getMessage()),
103 CallException.CODE_CALL_UNRECOVERABLE_FAULT,
104 ex);
105 }
106 return result;
107 }
108
109 /**
110 * Execute using the passed universe, rather than the loaded.
111 * @param uni a universe
112 * @return the result or null if there is no result
113 * @see autohit.universe.Universe
114 */
115 public String call(Universe uni) throws CallException {
116 return this.call();
117 }
118 }
|