Read the pid only once when stopping an instance

Review 718 by @mlucy
Closes #1115 again