I have a Java application running on a linux server. When it started, it recorded the process id to a "pidfile".
When I close it, I simply read the pid from that file, and kill it:
kill -9 12345
But other people says it is not safe, instead, they suggest me to embed a small http server, and provide a http api for closing, such as:
http://localhost:8080/close
When I want to close it, I need to visit it:
curl http://localhost:8080/close
It works but very boring, I still prefer the "process id" way. Is there any way to use process id to close the application safely?
Update:
"Safely" here I mean I can cancel some running tasks which may writing files to disk and close some resources before exiting.