>_ IzzyLab

Hands-on task

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

A pidfile for the preview service

medium~7 min

The server runs two Python services that look identical: the site preview and the documentation. The deploy script expects the PID of the preview service in /run/preview.pid, and the preview is the one listening on port 8002. The port number isn't in the processes' command lines: it comes from a config. Find the PID and write just the number to /run/preview.pid.

What you'll practise:
  • pidfile
  • ss -p
  • finding a process by port
  • grep -o
  • pid

Topic breakdown

A pidfile is a file with a single number, the PID of a process; control scripts use it to know whom to send signals to. Finding a PID by name is easy while the process is unique, but pgrep can't tell two instances of the same program apart if they differ only in config. The unambiguous mark of a network service is the port it listens on: ss with the show-processes option prints the owner's pid=… next to the socket, and a port filter leaves a single line. Only the number goes into the file, no spaces or extra lines — otherwise kill $(cat pidfile) breaks.

What's checked

  1. /run/preview.pid created
  2. the pidfile holds the PID of the process on port 8002

What it looks like