Ensure the process is properly terminated when the application closes