OLD | NEW |
| (Empty) |
1 /* | |
2 * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 * contributor license agreements. See the NOTICE file distributed with | |
4 * this work for additional information regarding copyright ownership. | |
5 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 * (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package org.apache.tomcat.jni; | |
19 | |
20 /** Proc | |
21 * | |
22 * @author Mladen Turk | |
23 */ | |
24 public class Proc { | |
25 | |
26 /* | |
27 * apr_cmdtype_e enum | |
28 */ | |
29 public static final int APR_SHELLCM = 0; /** use the shell to invoke th
e program */ | |
30 public static final int APR_PROGRAM = 1; /** invoke the program directl
y, no copied env */ | |
31 public static final int APR_PROGRAM_ENV = 2; /** invoke the program, replic
ating our environment */ | |
32 public static final int APR_PROGRAM_PATH = 3; /** find program on PATH, use
our environment */ | |
33 public static final int APR_SHELLCMD_ENV = 4; /** use the shell to invoke th
e program, | |
34 * replicating our environme
nt | |
35 */ | |
36 | |
37 /* | |
38 * apr_wait_how_e enum | |
39 */ | |
40 public static final int APR_WAIT = 0; /** wait for the specified process t
o finish */ | |
41 public static final int APR_NOWAIT = 1; /** do not wait -- just see if it ha
s finished */ | |
42 | |
43 /* | |
44 * apr_exit_why_e enum | |
45 */ | |
46 public static final int APR_PROC_EXIT = 1; /** process exited normall
y */ | |
47 public static final int APR_PROC_SIGNAL = 2; /** process exited due to
a signal */ | |
48 public static final int APR_PROC_SIGNAL_CORE = 4; /** process exited and dum
ped a core file */ | |
49 | |
50 public static final int APR_NO_PIPE = 0; | |
51 public static final int APR_FULL_BLOCK = 1; | |
52 public static final int APR_FULL_NONBLOCK = 2; | |
53 public static final int APR_PARENT_BLOCK = 3; | |
54 public static final int APR_CHILD_BLOCK = 4; | |
55 | |
56 public static final int APR_LIMIT_CPU = 0; | |
57 public static final int APR_LIMIT_MEM = 1; | |
58 public static final int APR_LIMIT_NPROC = 2; | |
59 public static final int APR_LIMIT_NOFILE = 3; | |
60 | |
61 | |
62 /** child has died, caller must call unregister still */ | |
63 public static final int APR_OC_REASON_DEATH = 0; | |
64 /** write_fd is unwritable */ | |
65 public static final int APR_OC_REASON_UNWRITABLE = 1; | |
66 /** a restart is occurring, perform any necessary cleanup (including | |
67 * sending a special signal to child) | |
68 */ | |
69 public static final int APR_OC_REASON_RESTART = 2; | |
70 /** unregister has been called, do whatever is necessary (including | |
71 * kill the child) | |
72 */ | |
73 public static final int APR_OC_REASON_UNREGISTER = 3; | |
74 /** somehow the child exited without us knowing ... buggy os? */ | |
75 public static final int APR_OC_REASON_LOST = 4; | |
76 /** a health check is occurring, for most maintenance functions | |
77 * this is a no-op. | |
78 */ | |
79 public static final int APR_OC_REASON_RUNNING = 5; | |
80 | |
81 /* apr_kill_conditions_e enumeration */ | |
82 /** process is never sent any signals */ | |
83 public static final int APR_KILL_NEVER = 0; | |
84 /** process is sent SIGKILL on apr_pool_t cleanup */ | |
85 public static final int APR_KILL_ALWAYS = 1; | |
86 /** SIGTERM, wait 3 seconds, SIGKILL */ | |
87 public static final int APR_KILL_AFTER_TIMEOUT = 2; | |
88 /** wait forever for the process to complete */ | |
89 public static final int APR_JUST_WAIT = 3; | |
90 /** send SIGTERM and then wait */ | |
91 public static final int APR_KILL_ONLY_ONCE = 4; | |
92 | |
93 public static final int APR_PROC_DETACH_FOREGROUND = 0; /** Do not detach */ | |
94 public static final int APR_PROC_DETACH_DAEMONIZE = 1; /** Detach */ | |
95 | |
96 /* Maximum number of arguments for create process call */ | |
97 public static final int MAX_ARGS_SIZE = 1024; | |
98 /* Maximum number of environment variables for create process call */ | |
99 public static final int MAX_ENV_SIZE = 1024; | |
100 | |
101 /** | |
102 * Allocate apr_proc_t structure from pool | |
103 * This is not an apr function. | |
104 * @param cont The pool to use. | |
105 */ | |
106 public static native long alloc(long cont); | |
107 | |
108 /** | |
109 * This is currently the only non-portable call in APR. This executes | |
110 * a standard unix fork. | |
111 * @param proc The resulting process handle. | |
112 * @param cont The pool to use. | |
113 * @return APR_INCHILD for the child, and APR_INPARENT for the parent | |
114 * or an error. | |
115 */ | |
116 public static native int fork(long [] proc, long cont); | |
117 | |
118 /** | |
119 * Create a new process and execute a new program within that process. | |
120 * This function returns without waiting for the new process to terminate; | |
121 * use apr_proc_wait for that. | |
122 * @param progname The program to run | |
123 * @param args The arguments to pass to the new program. The first | |
124 * one should be the program name. | |
125 * @param env The new environment table for the new process. This | |
126 * should be a list of NULL-terminated strings. This argument | |
127 * is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and | |
128 * APR_SHELLCMD_ENV types of commands. | |
129 * @param attr The procattr we should use to determine how to create the new | |
130 * process | |
131 * @param pool The pool to use. | |
132 * @return The resulting process handle. | |
133 */ | |
134 public static native int create(long proc, String progname, | |
135 String [] args, String [] env, | |
136 long attr, long pool); | |
137 | |
138 /** | |
139 * Wait for a child process to die | |
140 * @param proc The process handle that corresponds to the desired child proc
ess | |
141 * @param exit exit[0] The returned exit status of the child, if a child pro
cess | |
142 * dies, or the signal that caused the child to die. | |
143 * On platforms that don't support obtaining this information
, | |
144 * the status parameter will be returned as APR_ENOTIMPL. | |
145 * exit[1] Why the child died, the bitwise or of: | |
146 * <PRE> | |
147 * APR_PROC_EXIT -- process terminated normally | |
148 * APR_PROC_SIGNAL -- process was killed by a signal | |
149 * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and | |
150 * generated a core dump. | |
151 * </PRE> | |
152 * @param waithow How should we wait. One of: | |
153 * <PRE> | |
154 * APR_WAIT -- block until the child process dies. | |
155 * APR_NOWAIT -- return immediately regardless of if the | |
156 * child is dead or not. | |
157 * </PRE> | |
158 * @return The childs status is in the return code to this process. It is o
ne of: | |
159 * <PRE> | |
160 * APR_CHILD_DONE -- child is no longer running. | |
161 * APR_CHILD_NOTDONE -- child is still running. | |
162 * </PRE> | |
163 */ | |
164 public static native int wait(long proc, int [] exit, int waithow); | |
165 | |
166 /** | |
167 * Wait for any current child process to die and return information | |
168 * about that child. | |
169 * @param proc Pointer to NULL on entry, will be filled out with child's | |
170 * information | |
171 * @param exit exit[0] The returned exit status of the child, if a child pro
cess | |
172 * dies, or the signal that caused the child to die. | |
173 * On platforms that don't support obtaining this information
, | |
174 * the status parameter will be returned as APR_ENOTIMPL. | |
175 * exit[1] Why the child died, the bitwise or of: | |
176 * <PRE> | |
177 * APR_PROC_EXIT -- process terminated normally | |
178 * APR_PROC_SIGNAL -- process was killed by a signal | |
179 * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and | |
180 * generated a core dump. | |
181 * </PRE> | |
182 * @param waithow How should we wait. One of: | |
183 * <PRE> | |
184 * APR_WAIT -- block until the child process dies. | |
185 * APR_NOWAIT -- return immediately regardless of if the | |
186 * child is dead or not. | |
187 * </PRE> | |
188 * @param pool Pool to allocate child information out of. | |
189 */ | |
190 public static native int waitAllProcs(long proc, int [] exit, | |
191 int waithow, long pool); | |
192 | |
193 /** | |
194 * Detach the process from the controlling terminal. | |
195 * @param daemonize set to non-zero if the process should daemonize | |
196 * and become a background process, else it will | |
197 * stay in the foreground. | |
198 */ | |
199 public static native int detach(int daemonize); | |
200 | |
201 /** | |
202 * Terminate a process. | |
203 * @param proc The process to terminate. | |
204 * @param sig How to kill the process. | |
205 */ | |
206 public static native int kill(long proc, int sig); | |
207 | |
208 } | |
OLD | NEW |