Pilots go through YEARS of school, and THOUSANDS of hours of training, to be able to do one thing and one thing primarily – and that’s fly a plane.
This training means they’ve practiced flying a plane without a working engine… or without two working engines.
They’ve practiced failures on the ground. They simulate different failures in training flights. They go into a simulator and practice different failure scenarios – ad nauseum.
So when there’s a problem with that plane, that pilot is calm, controlled, and working his or her checklist of processes and procedures to get that plane under control. They’ll first be looking to restart the engine and regain thrust, so they can fly out of a problem.
If engine failure is inevitable, the pilot is doing everything in their power to determine the safest way and place to put the plane down. Sometimes that’s a beach, sometimes that’s a cornfield… sometimes that’s the middle of the Hudson River.
There is no ‘universal answer’ because every scenario is different. Chesley Sullenberger put his US Airways flight into the Hudson River after dual engine failure after taking off from LaGuardia in New York City…. No fatalities.

Whereas in 1983, Robert Pearson was at 41,000 feet altitude when he ran out of fuel due to a conversion error. He found an abandoned airstrip outside of Gimli, Manitoba and landed the plane with only minor injuries and no fatalities.
In 2001, an AirTransat 236 flight suffered a fuel leak over the Atlantic and became a glider… over 30 minutes of gradual descent and the pilot found an airstrip in the Azores Islands. Again, no fatalities or injuries.
Long story short: Pilots know what they’re doing and will do EVERYTHING they can to fly that bird safely to the ground.
SOURCE: QUORA