Giving a pilot a gun is not the answer. Guns in the hands on amateurs just cause more problems.
There's no way anyone is going to keep a suicidal nutter of an aeroplane, and allowing pilots to carry hand guns will just add to the problems...more innocent people will die as a result.... I'd rather have a couple of special forces, trained in use of firearms, sat at the front of each cabin, in uniform and body armour protecting the cockpit door if need be. But allowing a pilot to have a gun is a big mistake. His / her job is to fly the aeroplane, not act like Rambo. Leave that job to someone who's trained how to do it, and I don't mean some $30000 per year, straight off the street guy whos had 1 weeks training in the use of firearms.
The visible deterent of a couple of jugheads in body armour should be enough to deter a many of these nutters from trying anything, and if not then these guys are trained to deal with the situation.