What is the PID file format?
A .pid file is a small plain-text file used by Unix daemons and background services to record their own process ID (PID) at startup. The file contains a single decimal integer - the PID - optionally followed by a newline, making the typical file size just 2 to 10 bytes.
.pid files serve three practical purposes. First, they act as a lock: a service reads the file at startup and checks whether a process with that PID is still running, preventing duplicate instances. Second, they allow init scripts and service managers to send signals (SIGTERM, SIGHUP) to the correct process without a separate lookup. Third, monitoring tools use them to detect whether a service has crashed.
Files are conventionally stored in /var/run/ on Linux or /tmp/ on other Unix systems and named after the owning service - for example, nginx.pid or mysqld.pid. When the process exits cleanly it removes its own .pid file; a file left behind after a crash is called a *stale PID file* and must be removed before restarting the service.
Related formats include .lock files, which serve a similar mutual-exclusion role. Modern Linux systems running systemd increasingly rely on cgroup-based process tracking instead of .pid files, gradually reducing their use in newer service unit definitions.
Security & safety
RISK: LOWPID files are plain text containing only a number. They cannot execute and pose no security risk in themselves. Do not manually set arbitrary PIDs in a .pid file - services rely on the PID being accurate for signal delivery. Deleting a stale .pid is safe and necessary to unblock a service restart.
Format details
in a nutshellPrograms that open PID files
Technical details
deep spec| File content | Single decimal integer (the process ID), optionally followed by a newline |
| Typical file size | 2-10 bytes (Linux PIDs reach up to 4,194,304, requiring up to 7 digits) |
| Encoding | ASCII plain text; no binary data |
| Conventional storage path | /var/run/ on Linux; /tmp/ on other Unix systems |
| Naming convention | Named after the owning service, e.g., nginx.pid or mysqld.pid |
| Lifecycle | Created at daemon startup; removed on clean exit; left stale after a crash |
| Primary purposes | Prevent duplicate service instances; route signals (SIGTERM, SIGHUP) to the correct PID; enable health monitoring |
| Operating systems | Linux, macOS, BSD, Unix; some Windows daemons via WSL |
| Modern alternative | systemd cgroup tracking, which eliminates the need for PID files in new service unit files |
| MIME type | text/plain |
| File structure | Single-field plain text; no header, no schema, no binary structure |
| Released | 1980s (POSIX/Unix convention) |
| Latest version | N/A (no versioned spec) |
PID conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about PID files.