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.
Dummy example:
foo &
pid=$!
echo $pid > pidfile
do
kill $!
sleep 1 &
until [ $pid -eq $! ]
kill "$(cat pidfile)" # Kills
sleep
, not foo
!
Asked by l0b0
(53368 rep)
Apr 23, 2013, 12:54 PM
Last activity: Oct 28, 2015, 03:56 PM
Last activity: Oct 28, 2015, 03:56 PM