[EMAIL PROTECTED] wrote:
>
> Let me preface this by saying that this is a horrible hack--it seems
> to work for me today, but if you're interested, try it out and let me
> know...
>
> This is NOT 100% pure java. (there's a 4 line C program--ick!)
>
> I have done some research, and it doesn't appear that there is anyway
> to get the current process id from within java any other way. If
> anybody knows otherwise, let me know -- it will make this a lot
> simpler.
I don't know in java, but in bash you can get the pid of the process you
just launched in the background with "echo $!"
Sebastien
> The solution consists of 3 parts:
> a 4-line C program
> a couple of mods to org.jboss.Main
> some mods to run.sh and a new shutdown.sh and setvars.sh
>
> The source for the C program is as follows:
> int main() {
> printf("%i", getppid());
> return 0;
> }
>
> All this does is print out the process id of the process calling it
> (the parent process). Compile this, and put it in JBOSS_HOME/bin with
> the name 'getppid'
>
> in org.jboss.Main, add this to the beginning of the constructor:
> Runtime r = Runtime.getRuntime();
> Process p = r.exec(System.getProperty("jboss.home") +
> "/bin/getppid");
> BufferedReader bin = new BufferedReader(new
> InputStreamReader(p.getInputStream()));
> String line = bin.readLine();
> int pid = Integer.parseInt(line);
> PrintWriter out = new PrintWriter(new BufferedWriter(new
> FileWriter(System.getProperty("jboss.home") + "/tmp/jboss.pid")));
> out.print(pid);
>
> in.close();
> out.close();
>
> r = null;
> line = null;
>
> You'll also need to add an import for java.io.BufferedWriter to
> Main.java
> This calls our C program from above, and writes the output to a file
> in JBOSS_HOME/tmp/jboss.pid
>
> Next, create a file in JBOSS_HOME/bin called setvars.sh. Currently it
> consists of this:
> #!/bin/sh
>
> JBOSS_HOME=/opt/jboss
> export JBOSS_HOME
>
> Be sure to make it executable (chmod +x setvars.sh), and change to the
> actual location of your JBOSS_HOME.
>
> Add this near the top of run.sh:
> . ./setvars.sh
>
> Edit the last line of run.sh (where the java vm is launched) to
> include a '-Djboss.home=$JBOSS_HOME' (put it somewhere around the
> tomcat.home var)
>
> Create a new file called shutdown.sh, executable with these contents:
> #!/bin/sh
>
> . ./setvars.sh
>
> getpid() {
> pid=`cat $JBOSS_HOME/tmp/jboss.pid`
> echo $pid
> return 0
> }
>
> thispid=`getpid`
> kill $thispid
>
> This seems to do the trick. There's some obvious room for
> improvement here and there.... (such as cleaning up the .pid file,
> etc.) I have no idea if this will work under Windows or not (I don't
> have a C compiler for windows)--anybody care to comment?
>
> It should now be trivial to set up start and stop scripts for your
> system that just call run.sh and shutdown.sh....
>
> -Jason
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]