It is narrated from Hazrat Anas (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: Allah Almighty has appointed an angel over the womb of the mother, who at its appointed time keeps saying: O Lord! Now it has become a drop of fluid; O Lord! Now it has become a clot of flesh. Then when Allah intends to create it, the angel asks: O Lord! Will it be wretched or blessed? Will it be male or female? And how long will its lifespan be? All these things are written in the mother's womb.
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 12499