#1745: Adds check to only write pidfile on succuess exec

See issue #1745.

- Tom