If you are armed with a pistol and manage to predict the attack before the attacker gets too close, you draw the pistol and shoot your attacker!
There is an invisible buffer zone before you enter the hotzone from a reaction time point of view: With the objective to neutralize the attacker before getting stabbed, you need to prioritize.
Once you sense the close danger, you need to use impact strike on your assailant! Whichever is more convenient, either hit first and reach with your free hand to block the knife holding hand, or block the knife holding hand and reach to strike your attacker almost at the same split second in the head area.
Remember to use a stable fist(tighten your forearm muscles) if you are punching to the chin or cheek) in a whip motion to ensure the maximum speed is maintained during impact. In addition remember to shift your body weight to the direction you are sending your impact starting when you almost reach the impact point. You need to pass your target about 5 inches. Keep in mind however, that the knife does not need support of the attacker's weight so it could move faster than your punching. Therefore consider the knife positioning and make a judgement call weather to block first, or strike first...
Although the shoulder twist and the weight shift to the striking side of the body is the most efficient way to do it, you need to consider maneuvering around your other hand holding the attacker's wrist of the knife holding hand.
If you lunge from a greater distance you can kick to the groin if you are facing your opponent, or to the knee if he is sidewise to you. If you see a knife reaching your throat from behind you, an elbow to his lungs might be a faster response than trying to block him, since your arm is to the side of your body, and the knife is appearing suddenly over your shoulder!
Other possibilities again according to your stance and body positioning relative to your opponent, when you noticed the danger include striking the attacker with the tip of the barrel in the throat or chest if he is approaching from the front or side(according to your gun positioning) or raising your rifle held with both hands and striking the opponent's chin or cheek with the magazine from the closer range. You can use the butt of the rifle to strike backwards and to the side as well!
If you notice an attacker attacking other fellow men trying to stab them with a knife, you can run at him and use your last step to lunge a front kick in his groin or tailbone, according to his body positioning as you close the gap! If you have a rifle, you can shoot, or use it for a strike. Remember to move in quickly and finish him after the initial impact with a strike to the head according to his follow up immediate positioning. Follow the same principles of impact generation.
The front kick has a seesaw motion for weight shifting purpose and the side kick used should have a corkscrew motion! You need to tense the ankle muscles prior to a kick to ready for the impact and place the positioning of the foot as well ahead of the kick with either ball of the foot or heel!
If you use your elbow to strike someone behind you, lift your arm forward quickly point your arm backward and poke with retraction to maintain the speed during the impact. Also lift your opposite foot off the ground maintaining a straight leg will help shift the body weight with the impact. The total effect of using a Ram!
Remember your mission is not to get killed. You need to chose your weapon when the element of surprise is not on your side! You need to use whatever is feasible to work in the few splits seconds you have left if you have them.
Now you need to consider what is quicker: To harm your opponent, or to block the knife - whichever has a quicker reach when you notice it!
Hope you will never have to use it, and perhaps it will motivate you to get some training and maybe make you realize you need to give it a try as a last resort choice, as sometimes it is faster to lunge and kick forward, as to turn or run backwards and you just don't have that extra time or extra endurance even if you had that time!