1

I have a script:

#!/bin/bash
/my-path/to/long-running-process/start-server

This starts up a JVM server which is supposed to keep working after the bash script terminates. How can I get the PID of the JVM process from within the same bash script so I can write it to a file in case I need to kill it later?

Zuriar
  • 11,096
  • 20
  • 57
  • 92
  • Possible duplicate of [How to get the process id of command executed in bash script?](http://stackoverflow.com/questions/21532233/how-to-get-the-process-id-of-command-executed-in-bash-script) – AlG Mar 30 '16 at 15:07

1 Answers1

2

The bash manual covers this under Special Parameters:

#!/bin/bash

/my-path/to/long-running-process/start-server &

echo $! > /path/to/your/pid/file.pid
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • Thanks - If a script that is called from inside a script itself starts a process is it possible to have the PID filter down to the original script? – Zuriar Mar 31 '16 at 07:31