Improved handling of popen process termination