Fix runaway emulator subprocess

This commit fixes the issue of the emulator subprocess continuing to run
after the main process exits by adding an exit handler which terminates
the subprocess.