Stale PID file after reboot
linux, pid
Solution
Often, pidfiles are written into `/var/run/` or `/run/` (on many systems there is a symlink from `/var/run` to `/run` so they are the same). See the Filesystem Hierarchy Standard for more. And that `/run/` directory is supposed to be cleared early at boot-time (i.e. because it is mounted as `tmpfs`), so it won't survive a reboot. See also the Linux Standard Base 4.1 specification.
Hence you should not care about stale pidfiles. This should not happen, and if it does it probably is because the sysadmin messed something up badly. I would just exit with some kind of an error message if that pidfile already exists.
Problem
How do I deal with a stale pidfile after a reboot? I'm thinking I can't trust the number in the file, since another process may have taken its place with the same PID. Can/should I ensure pidfiles don't survive a reboot? What's the proper way of detecting a stale pidfile, that may or may not be left over from a previous boot, when a process with that pid is running?