KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > jni > Proc


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  * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
24  */

25
26 public class Proc {
27
28     /*
29      * apr_cmdtype_e enum
30      */

31     public static final int APR_SHELLCM = 0; /** use the shell to invoke the program */
32     public static final int APR_PROGRAM = 1; /** invoke the program directly, no copied env */
33     public static final int APR_PROGRAM_ENV = 2; /** invoke the program, replicating our environment */
34     public static final int APR_PROGRAM_PATH = 3; /** find program on PATH, use our environment */
35     public static final int APR_SHELLCMD_ENV = 4; /** use the shell to invoke the program,
36                                                    * replicating our environment
37                                                    */

38
39     /*
40      * apr_wait_how_e enum
41      */

42     public static final int APR_WAIT = 0; /** wait for the specified process to finish */
43     public static final int APR_NOWAIT = 1; /** do not wait -- just see if it has finished */
44
45     /*
46      * apr_exit_why_e enum
47      */

48     public static final int APR_PROC_EXIT = 1; /** process exited normally */
49     public static final int APR_PROC_SIGNAL = 2; /** process exited due to a signal */
50     public static final int APR_PROC_SIGNAL_CORE = 4; /** process exited and dumped a core file */
51
52     public static final int APR_NO_PIPE = 0;
53     public static final int APR_FULL_BLOCK = 1;
54     public static final int APR_FULL_NONBLOCK = 2;
55     public static final int APR_PARENT_BLOCK = 3;
56     public static final int APR_CHILD_BLOCK = 4;
57
58     public static final int APR_LIMIT_CPU = 0;
59     public static final int APR_LIMIT_MEM = 1;
60     public static final int APR_LIMIT_NPROC = 2;
61     public static final int APR_LIMIT_NOFILE = 3;
62
63
64     /** child has died, caller must call unregister still */
65     public static final int APR_OC_REASON_DEATH = 0;
66     /** write_fd is unwritable */
67     public static final int APR_OC_REASON_UNWRITABLE = 1;
68     /** a restart is occuring, perform any necessary cleanup (including
69      * sending a special signal to child)
70      */

71     public static final int APR_OC_REASON_RESTART = 2;
72     /** unregister has been called, do whatever is necessary (including
73      * kill the child)
74      */

75     public static final int APR_OC_REASON_UNREGISTER = 3;
76     /** somehow the child exited without us knowing ... buggy os? */
77     public static final int APR_OC_REASON_LOST = 4;
78     /** a health check is occuring, for most maintainence functions
79      * this is a no-op.
80      */

81     public static final int APR_OC_REASON_RUNNING = 5;
82
83     /* apr_kill_conditions_e enumeration */
84     /** process is never sent any signals */
85     public static final int APR_KILL_NEVER = 0;
86     /** process is sent SIGKILL on apr_pool_t cleanup */
87     public static final int APR_KILL_ALWAYS = 1;
88     /** SIGTERM, wait 3 seconds, SIGKILL */
89     public static final int APR_KILL_AFTER_TIMEOUT = 2;
90     /** wait forever for the process to complete */
91     public static final int APR_JUST_WAIT = 3;
92     /** send SIGTERM and then wait */
93     public static final int APR_KILL_ONLY_ONCE = 4;
94
95     public static final int APR_PROC_DETACH_FOREGROUND = 0; /** Do not detach */
96     public static final int APR_PROC_DETACH_DAEMONIZE = 1; /** Detach */
97
98     /* Maximum number of arguments for create process call */
99     public static final int MAX_ARGS_SIZE = 1024;
100     /* Maximum number of environment variables for create process call */
101     public static final int MAX_ENV_SIZE = 1024;
102
103     /**
104      * Allocate apr_proc_t stucture from pool
105      * This is not an apr function.
106      * @param cont The pool to use.
107      */

108     public static native long alloc(long cont);
109
110     /**
111      * This is currently the only non-portable call in APR. This executes
112      * a standard unix fork.
113      * @param proc The resulting process handle.
114      * @param cont The pool to use.
115      * @return APR_INCHILD for the child, and APR_INPARENT for the parent
116      * or an error.
117      */

118     public static native int fork(long [] proc, long cont);
119
120     /**
121      * Create a new process and execute a new program within that process.
122      * This function returns without waiting for the new process to terminate;
123      * use apr_proc_wait for that.
124      * @param progname The program to run
125      * @param args The arguments to pass to the new program. The first
126      * one should be the program name.
127      * @param env The new environment table for the new process. This
128      * should be a list of NULL-terminated strings. This argument
129      * is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and
130      * APR_SHELLCMD_ENV types of commands.
131      * @param attr The procattr we should use to determine how to create the new
132      * process
133      * @param pool The pool to use.
134      * @return The resulting process handle.
135      */

136     public static native int create(long proc, String JavaDoc progname,
137                                     String JavaDoc [] args, String JavaDoc [] env,
138                                     long attr, long pool);
139
140     /**
141      * Wait for a child process to die
142      * @param proc The process handle that corresponds to the desired child process
143      * @param exit exit[0] The returned exit status of the child, if a child process
144      * dies, or the signal that caused the child to die.
145      * On platforms that don't support obtaining this information,
146      * the status parameter will be returned as APR_ENOTIMPL.
147      * exit[1] Why the child died, the bitwise or of:
148      * <PRE>
149      * APR_PROC_EXIT -- process terminated normally
150      * APR_PROC_SIGNAL -- process was killed by a signal
151      * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
152      * generated a core dump.
153      * </PRE>
154      * @param waithow How should we wait. One of:
155      * <PRE>
156      * APR_WAIT -- block until the child process dies.
157      * APR_NOWAIT -- return immediately regardless of if the
158      * child is dead or not.
159      * </PRE>
160      * @return The childs status is in the return code to this process. It is one of:
161      * <PRE>
162      * APR_CHILD_DONE -- child is no longer running.
163      * APR_CHILD_NOTDONE -- child is still running.
164      * </PRE>
165      */

166     public static native int wait(long proc, int [] exit, int waithow);
167
168     /**
169      * Wait for any current child process to die and return information
170      * about that child.
171      * @param proc Pointer to NULL on entry, will be filled out with child's
172      * information
173      * @param exit exit[0] The returned exit status of the child, if a child process
174      * dies, or the signal that caused the child to die.
175      * On platforms that don't support obtaining this information,
176      * the status parameter will be returned as APR_ENOTIMPL.
177      * exit[1] Why the child died, the bitwise or of:
178      * <PRE>
179      * APR_PROC_EXIT -- process terminated normally
180      * APR_PROC_SIGNAL -- process was killed by a signal
181      * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
182      * generated a core dump.
183      * </PRE>
184      * @param waithow How should we wait. One of:
185      * <PRE>
186      * APR_WAIT -- block until the child process dies.
187      * APR_NOWAIT -- return immediately regardless of if the
188      * child is dead or not.
189      * </PRE>
190      * @param pool Pool to allocate child information out of.
191      */

192     public static native int waitAllProcs(long proc, int [] exit,
193                                           int waithow, long pool);
194
195      /**
196      * Detach the process from the controlling terminal.
197      * @param daemonize set to non-zero if the process should daemonize
198      * and become a background process, else it will
199      * stay in the foreground.
200      */

201     public static native int detach(int daemonize);
202
203     /**
204      * Terminate a process.
205      * @param proc The process to terminate.
206      * @param sig How to kill the process.
207      */

208     public static native int kill(long proc, int sig);
209
210 }
211
Popular Tags