Fix pidfile error handling

throw error when writing to pidfile fails