Location of PID file (or executable) at runtime
nginx-forum at nginx.us
Wed Apr 7 17:24:15 MSD 2010
I'm looking for a way to find the fully qualified path of the "PID" file at run time. Basically, I've got some code that I need to run when the server is starting, and some different code I need to run when the server is shutting down (daemon mode).
I use fopen("logs/nginx.pid", "r") == NULL to decide if the file exists of not.
If it doesn't, I assume the server is starting. If it does, I assume the server is shutting down. I am aware that this code must execute before the pid file is created to work, which it does. This all works fine, except the location I'm starting it from must be relative to the path I give in fopen. Thus, I have to start it in the same folder as logs, usually by saying sbin/nginx. I want to be able to start it from anywhere, thus I want to use the fully qualified path of the pid file instead of it's relative path. I suppose even if I knew the full executable path, I could escape it one level up and tack on logs/nginx.pid but knowing the pid itself would likely be better.
So does nginx make the location of the pid file available at run time? Is there a way I can extract the full location of the PID (or exe) at run time? Thanks!
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,72311,72311#msg-72311
More information about the nginx