Let's say I came across this kind of situation. What do I do?
There are techniques to do so, and why not learn them, but understand the math on not getting shot is very pessimistic, such that if you try to apply them in real life, you almost certainly get shot.
The movies show such techniques routinely, and it's a major part of serious "gun fu" fight choreography, but remember they're doing things like disassembling a loaded pistol held by the opponent, and so alway should be taken with a grain of salt.
If I was a significantly more proficient grappler than the assailant, and assumed they were going to kill me anyway, I would wait until the muzzle is off target and move in a manner so as to control their wrist, keeping the muzzle off-target, and removing it from their hand by whatever method was most expedient, but I'd still assume I was going to die.
One possible option, if you just want to avoid being a hostage, is to make yourself an inconvenient hostage. Faint (or fake doing so) when the gun isn't pointed at your head. Vomit in fear. Lose control of your bowels. Unless you're the only option, the criminal isn't going to want to drag dead weight along, or deal with the smell. And most hostage takers really don't want to shoot someone. They want to get away, preferably with their loot.