I currently am starting a Java process, and am trying to get its PID using $!, and writing that to a file. The problem is, when I start the Java process, it goes into its own “console”. (I’m not sure what this is called).
I’m not able to write this $! to a file until I have stopped the process and exited out of its “console”, where the PID is then useless.
How would I go about starting the Java process, and getting its PID without ending it?
I am using echo $! > pidfile.pid to write the PID of the Java process to a file.
Write small Java wrapper starter java.sh (for example):
In short shell script writes out its PID and then replaces itself with java process with all parameters that you pass to shell script. Then simply replace java with java.sh in your scripts… and of course you can pass pidfile through exported variable.