Reputation: 3
Am hosting a jar file in GCP and everytime I make a change in the file ofcourse i would need to update the jar, but everytime I run the with the command nohup java -jar java.jar &>> logy.log &
this run the file in background and gives a processes ID which is required to kill the process if I want to rerun the file when I make some changes. But once I restart the linux server I cannot find the process with the command bg
and I tried looking for several other commands on google but none seem to have help. I need a consitent way of killing the process rather than writting the process ID somewhere everytime I run the file.
Upvotes: 0
Views: 200
Reputation: 3147
Can be use process API, that added in Java 9. Process id can be obtain from:
long process_id = ProcessHandle.current().pid();
Upvotes: 1
Reputation: 154
Generally, applications create a PID file that includes the PID and then kill with that info. If you don't want to use this approach, maybe you can go with pkill.
Upvotes: 0