Fix bug in monkeypatched `reply()`

Write/remove PID file

Add handler for uncaught exceptions