>_ IzzyLab

Hands-on task

This task is step 18 of the course “Processes and signals”

A pidfile from a dead process

easy~3 min

The report daemon won't start: /opt/reporter/start.sh answers already running (pid 31337). But there's no such process — the daemon crashed overnight, and its pidfile /run/reporter.pid was left behind. Make sure the process with that PID really is dead, remove the stale pidfile and start the daemon via start.sh.

What you'll practise:
  • pidfile
  • kill -0
  • ps -p
  • daemons
  • stale lock

Topic breakdown

A pidfile is a file with the PID of a running daemon: from it, control scripts know the daemon is running and whom to send signals to. If the process died abnormally (SIGKILL, OOM, a crash), it doesn't get to delete the pidfile, and a simple start script keeps thinking the daemon is alive. You can check whether a process exists with the "null signal" kill -0 PID: it delivers nothing and only returns success if the process exists. Once you're sure the PID is dead, the stale pidfile is removed — otherwise you risk starting a second instance on top of a live one.

What's checked

  1. the daemon is running
  2. the pidfile points to the live daemon

What it looks like