fix terminate process race condition