Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

What are pid and lock files for?

I often see that programs specify pid and lock files. And I'm not quite sure what they do.

For example, when compiling nginx:

--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \

Can somebody shed some light on this one?

Answer*

Cancel
3
  • 1
    +1 Explaining the use of having both the lock file and the pid file. Commented Oct 6, 2015 at 2:00
  • 2
    @Caleb - Please explain why both a PID file and a lock file would be used. It seems a PID file would be sufficient. If the PID file exists, the PID could be checked to see if the process is running, just takes less steps than check for a lockfile, checking for a PID file, and then verifying the existence of the process. Commented Jan 25, 2017 at 16:57
  • 2
    @MVaughan To avoid race conditions if nothing else. Some apps have uses for times when the still need the PID but can relinquish the lock. But at a more fundamental level if you overload one file for both operations you open the door to failures such as a crash leaving an inconsistent state on the system. Commented Jan 25, 2017 at 21:06