In modern practice WHEN AND HOW long CPR should be done? Terminal event If a patient is brought dead then WHAT?

(Majority of attack on Doctors in Emergency Room by relatives and crowd happens in this tricky situation).