It seems many programmers are happy with saving a PID to a file, and then later read and use the PID as if it was guaranteed to be the same process. It seems the general idea is that the odds are good enough to ignore. How can I simply demonstrate this problem? Ideally in such a way that existing shell scripts can be adapted to demonstrate this with the minimum of trial and error.
foo & pid=$! echo $pid > pidfile do kill $! sleep 1 & until [ $pid -eq $! ] kill "$(cat pidfile)" # Kills `sleep`, not `foo`!