0

In the start script for my application, the service is started with the following lines:

JVM_OPTS=$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$${optsEnvironmentVar}" -Dapp.pid=$$ -Dapp.home=$APP_HOME -Dbasedir=$APP_HOME"

exec nohup "$JAVACMD" -jar $JVM_OPTS <% if ( appNameSystemProperty ) { %>\"-D${appNameSystemProperty}=$APP_BASE_NAME\" <% } %> $CLASSPATH server /resources/config.yml >  /home/testUser/stdout.out 2>  /home/testUser/stderr.err &

The application starts up fine, but on code review, we noticed that the value of -Dapp.pid was incorrect, by checking it in ps -aux | grep appName, and comparing it to the PID of that command, along with the PID outputed by pgrep -f appName. I would like to know if there is any way to assign the correct PID to the parameter. So far, I've tried setting it to be:

-Dapp.pid=`preg -f appName`

But that simply ends up with -Dapp.pid being blank, which I assume is due to it calling that command before the exec is fully run. Has anyone else come across this before?

SVill
  • 331
  • 5
  • 22
  • 55
  • 1
    Do you really want to pass PID of a not-yet-created process as an argument to this process? Hmm... – apangin Aug 28 '19 at 18:45
  • 1
    You cannot know the PID of the process until you start it. Detect the PID of the process directly from the java. See for example [here](https://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id) – gudok Aug 28 '19 at 18:45

0 Answers0