Before we went to Abyssinia we used to greet God’s Messenger when he was engaged in prayer and he would respond to us, but when we returned from Abyssinia I came to him and found him praying. I greeted him and he did not respond to me, but when he finished his prayer he said, “God creates new commands as He wishes, and one of them is that you must not talk during prayer.” He then returned my greeting and said, “Prayer is solely for the purpose of reciting the Qur’an and making mention of God, so when you are engaged in it let that be what occupies your attention.”
Sahl b. Sa‘d reported God's Messenger as saying, “If anything happens to someone during prayer he should say, ‘Glory be to God,’ for clapping applies only to women.” In a version he said, “Saying 'Glory be to God’ applies to men and clapping to women.”
Ibu ‘Umar said he asked Bilal how the Prophet responded to them when they greeted him while he was engaged in prayer, and he replied, “He used to make a sign with his hand.”
Tirmidhi transmitted it. In Nasa'i’s version there is something similar, but Suhaib occurs instead of Bilal.
Abu Huraira reported God’s Messenger as saying, “An ‘ifrit of the jinn escaped yesterday to interrupt my prayer, but God gave me power over him, so I seized him and intended to tie him to one of the pillars of the mosque in order that you might all look at him; but I remembered the supplication of my brother Solomon, ‘My Lord, give me such a kingdom as will not be fitting for anyone after me’ (Al-Qur’an; 38:35) so I made him clear out.”