Ensure process terminate is only called after checking whether the
process is still running so as not to accidentally set an exitcode.
Additionally include improved message exchange and capturing to allow
for easier debug should the expected exceptions not appear on socket
timeouts.
Change-Id: Ic51745ffa67570e9a3ca4574d2bfc54d0cd6724b