Interview Prep/Linux/Processes, services and systemd

A daemon writes a PID file and ops scripts use it, but after crashes the stale PID points to a different process. How do you fix the design?

AdvancedScenarioProcesses, services and systemd
Answer

Situation read → PID files are racy; let the supervisor track the process.

What I'd do →

  1. Run the daemon in the foreground under systemd (Type=simple/notify), which tracks it by cgroup.
  2. Scripts use systemctl is-active app, systemctl kill app or systemctl show -p MainPID app.
  3. If PID files must stay, put them in /run (cleared at boot) via RuntimeDirectory=app.

Why → cgroup tracking can't confuse processes, and /run is a tmpfs, so stale files vanish on reboot.

Interview tip → "Let systemd own process lifecycle" is the senior answer.

All Linux questions Roadmap: Linux

More on Processes, services and systemd