I’ve had a fair bit of training on both how to use a knife and how to defend against them.
There are a few basic skills involved that need to be learned but beware of the “internet trainers and experts” especially on youtube.
First rule of fighting with or against a knife is that you’re going to get cut and you’re going to have to be able to fight through that to survive.
Gun vs knife? Keep your distance, he can’t hurt you if he can’t reach you.
Keep in mind too, you are under no obligation to let them close to arms length either before using deadly force to stop them.
Remember too that in such a scenario you have no lawful use of deadly force unless the threat is imminent and immediate so if you start shooting when the bad guy is fifty yards away waiving a knife around threatening you there is no lawful use of DF.
In this scenario, third party defense things get very complicated and you’re probably going to have to make a perfect shot to stop the bad guy without injuring the innocent.
Don’t be afraid to look at alternative targets like the feet, knees, hips etc either if the chance arises and the knife is not to the subject’s neck etc.
Pain is a great motivator and taking out their landing gear is a great way to get them to release the innocent.