Reputation: 20242
I have the following script:
java -cp "some-classpath" my.package.MyClass
echo $1 > "$java_file"
The Java process starts a server.
I would like to get the process ID of the Java command and to write it to the file $java_file
. Then, using that, I will kill the server.
However, nothing is written in the file.
How can I get the process ID?
Upvotes: 3
Views: 99
Reputation: 15862
You should use:
java -cp "some-classpath" my.package.MyClass &
echo $! > "$java_file"
Upvotes: 4