1

The PID file for this statement is created but it is always empty. When running the shell with -x I see that $! empty, yet at the end the java job is left running in the background as desired. Why is the pid missing?

 su - $USER -c "nohup java $rest_api_opts -jar $app_home/$app_name \
   > /dev/null 2>&1& echo $! > $PID"
Neil H Watson
  • 450
  • 1
  • 5
  • 17

1 Answers1

2

Fixed. The trouble is that $! is expanded too early. So escaping it delayed the expansion

su - $USER -c "nohup java $rest_api_opts -jar $app_home/$app_name \
   > /dev/null 2>&1& echo \$! > $PID"
Neil H Watson
  • 450
  • 1
  • 5
  • 17